Skip to content

Conversation

@klecki
Copy link
Contributor

@klecki klecki commented Jan 14, 2026

Category: New feature

Description:

The operator now supports optional argument to set the layout. The *_like(...) variants take the layout from the data_like input.

Documentation is added to explain that the fill_value is broadcast.

Additional information:

Affected modules and functionalities:

ConstatValue family of operators.

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

The operator now supports optional argument to set the layout.
The *_like(...) variants take the layout from the `data_like` input.

Documentation is added to explain that the fill_value is broadcast.

Signed-off-by: Krzysztof Lecki <[email protected]>
@greptile-apps
Copy link

greptile-apps bot commented Jan 14, 2026

Greptile Summary

This PR adds layout handling to the Full, Zeros, and Ones operator family, allowing users to specify output layouts and automatically propagate layouts from *_like variants.

Key changes:

  • Adds optional layout argument to Full, Zeros, and Ones operators with validation that ensures layout dimensionality matches output shape
  • *Like operators now automatically copy layout from the data_like input tensor
  • Documentation updated to clarify that fill_value supports NumPy-style broadcasting
  • Comprehensive test coverage added for layout propagation, empty layouts, and mismatch scenarios

Implementation details:

  • Layout is applied in RunImpl after data generation (lines 148-152 in constant_value.cc)
  • Layout validation occurs during SetupImpl to catch mismatches early (lines 114-118 in constant_value.h)
  • The implementation follows DALI's existing layout handling patterns from recent refactorings

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean and follows existing DALI patterns. Layout validation is performed during setup to catch errors early. Comprehensive test coverage includes positive cases, edge cases (empty layouts), and error scenarios. The changes are well-contained to the constant value operator family.
  • No files require special attention

Important Files Changed

Filename Overview
dali/operators/generic/constant_value.h Adds layout support with proper member variables, validation in SetupImpl, and clear constructor documentation
dali/operators/generic/constant_value.cc Updates RunImpl to set layout from argument or data_like input, adds comprehensive documentation about broadcasting
dali/test/python/operator_1/test_constant_value.py Comprehensive test coverage for layout handling including propagation, empty layouts, and mismatch validation

Sequence Diagram

sequenceDiagram
    participant User
    participant Pipeline
    participant ConstantValue as ConstantValue Operator
    participant SetupImpl
    participant RunImpl
    participant Output

    User->>Pipeline: fn.full/zeros/ones(shape, layout="HWC")
    Pipeline->>ConstantValue: Constructor(spec)
    ConstantValue->>ConstantValue: Extract has_layout_ flag
    ConstantValue->>ConstantValue: Store layout_ if defined
    
    Pipeline->>SetupImpl: SetupImpl(ws)
    SetupImpl->>SetupImpl: Determine output shape
    SetupImpl->>SetupImpl: Determine output dtype
    
    alt layout argument provided
        SetupImpl->>SetupImpl: Validate layout.ndim() == shape.sample_dim()
        SetupImpl-->>Pipeline: Throw error if mismatch
    end
    
    SetupImpl-->>Pipeline: Return OutputDesc
    
    Pipeline->>RunImpl: RunImpl(ws)
    
    alt has_fill_value
        RunImpl->>RunImpl: Broadcast fill_value to output shape
    else constant value (zeros/ones)
        RunImpl->>RunImpl: Fill with const_value_
    end
    
    alt has_layout_
        RunImpl->>Output: SetLayout(layout_)
    else is_shape_like_
        RunImpl->>Output: SetLayout from data_like input
    end
    
    RunImpl-->>Pipeline: Complete
    Pipeline-->>User: Return tensor with layout
Loading

@klecki
Copy link
Contributor Author

klecki commented Jan 14, 2026

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [41749827]: BUILD STARTED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants