|
Stratax 0.3.1
|
Version: v0.2.0
Status: Complete
Header: include/stratax/ops/Broadcasting.hpp
Broadcasting.hpp defines shape compatibility, result-shape calculation, and element-wise traversal for operands with different but compatible shapes.
Shapes align from the trailing dimension. Two aligned dimensions are compatible when they are equal or either dimension has length one. Missing leading dimensions behave as dimensions of length one.
The broadcasting module is responsible for:
Exceptions::BroadcastErrorThe broadcasting module is not responsible for:
Depends on:
include/stratax/core/dtypes/Concepts.hppinclude/stratax/core/Shape.hppinclude/stratax/exceptions/Exceptions.hppUsed by:
include/stratax/ops/Arithmetic.hppDimensions are compared from right to left:
For each aligned pair:
During traversal, an expanded singleton dimension always reads coordinate zero from its source operand.
The following conditions are always true:
Exceptions::BroadcastError.Returns true when every aligned dimension pair is compatible. This function does not throw for ordinary incompatibility.
Complexity
Throws
Exceptions::BroadcastError when the shapes are incompatibleComplexity
Both arrays must have the same container and element type. The callable receives the projected left and right values for each output coordinate.
Throws
Exceptions::BroadcastError when the shapes are incompatibleopComplexity
The callable receives each array value followed by the scalar. The result shape matches lhs.
Complexity
The callable receives the scalar followed by each array value. The result shape matches rhs.
Complexity
| Operation | Complexity |
|---|---|
| Shape validation | O(r) |
| Result-shape calculation | O(r) |
| Array-array operation | O(nr) |
| Array-scalar operation | O(n) |
| Scalar-array operation | O(n) |
n is result element count and r is result rank.
The functions are also available through the grouped stratax::broadcasting namespace.
The public shape operations remain separate from traversal so callers can validate or inspect a result shape without allocating a result array.
Flat operand offsets are computed from output coordinates without allocating a coordinate vector for each element.