|
Stratax 0.3.1
|
Version: v0.2.0
Status: Complete
Header: include/stratax/ops/Comparison.hpp
Comparison.hpp provides element-wise equality and ordering comparisons for Stratax arrays. Every comparison returns a newly allocated array whose dtype is stratax::dtype::bool_; it does not reduce the result to one Boolean value.
The API supports all operand arrangements:
Array-array comparisons follow Stratax broadcasting rules and may mix Vector, Matrix, and Tensor operands. Array-scalar comparisons preserve the array operand's container type and shape.
The comparison module is responsible for:
The comparison module is not responsible for:
boolDepends on:
include/stratax/core/dtypes/Concepts.hppinclude/stratax/core/ArrayTraits.hppinclude/stratax/core/dtypes/Types.hppinclude/stratax/ops/Broadcasting.hppThe following conditions are always true:
promote_array_t to select the result container.== operation.Ordered.The result container is stratax::core::promote_array_t<L, R, stratax::dtype::bool_>. Its shape is the common broadcasted shape.
Throws
Exceptions::BroadcastError when the operand shapes are incompatibleComplexity
n is the result element count and r is the result rankEquality and inequality accept any DType scalar:
Ordering overloads use the same operand arrangements but require the scalar and array value type to satisfy Ordered:
The result type is stratax::core::rebind_array_t<A, stratax::dtype::bool_>. No broadcasting is needed because the scalar is applied to every array element.
Complexity
n is the array element countAll named comparisons have equivalent operator syntax for array-array, array-scalar, and scalar-array operands:
The operators return the same Boolean array type as their corresponding named function. In particular, lhs == rhs is an element-wise operation and cannot be used directly as a single Boolean condition.
Implementation helpers live in stratax::core::comparison_detail:
comparison_op performs broadcasted array-array traversal.comparison_scalar_op implements both scalar operand orders.array_equal performs internal whole-array shape and value equality.These helpers are implementation details and are not part of the public API.
| Operation | Complexity |
|---|---|
| Array-array comparison | O(nr) |
| Array-scalar comparison | O(n) |
| Scalar-array comparison | O(n) |
| Internal whole-array equality | O(r + n) worst case |
For broadcasted operations, n is the result size and r is the result rank. For scalar operations, n is the array size.
Because comparisons return arrays, callers that need one Boolean value should explicitly reduce or inspect the mask rather than treating it as a bool:
Equality remains exact for floating-point and complex values. Approximate comparison should be exposed as a separate, explicit algorithm so tolerance selection is visible at the call site.
Complex dtypes support equal, not_equal, ==, and !=. They do not satisfy Ordered, so <, <=, >, and >= are rejected at compile time.
all and any Boolean reductions for whole-mask queries