Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Comparison.hpp File Reference

Element-wise boolean comparisons with broadcasting. More...

Include dependency graph for Comparison.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<Array L, Array R, typename Op >
auto stratax::core::comparison_detail::comparison_op (const L &lhs, const R &rhs, Op op)
 Applies an element-wise comparison to two broadcast-compatible arrays.
 
template<Array A, DType Scalar, typename Op >
auto stratax::core::comparison_detail::comparison_scalar_op (const A &lhs, const Scalar &rhs, Op op)
 Compares every array element with a scalar on the right.
 
template<DType Scalar, Array A, typename Op >
auto stratax::core::comparison_detail::comparison_scalar_op (const Scalar &lhs, const A &rhs, Op op)
 Compares a scalar on the left with every array element.
 
template<Array L, Array R>
bool stratax::core::comparison_detail::array_equal (const L &lhs, const R &rhs)
 Tests whether two arrays have identical shapes and element values.
 
template<Array L, Array R>
auto equal (const L &lhs, const R &rhs)
 Compares two arrays for element-wise equality with broadcasting.
 
template<Array L, Array R>
auto not_equal (const L &lhs, const R &rhs)
 Compares two arrays for element-wise inequality with broadcasting.
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto less (const L &lhs, const R &rhs)
 Tests each broadcasted left element for strict ordering below the corresponding right element.
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto less_equal (const L &lhs, const R &rhs)
 Tests each broadcasted left element for ordering below or equal to the corresponding right element.
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto greater (const L &lhs, const R &rhs)
 Tests each broadcasted left element for strict ordering above the corresponding right element.
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto greater_equal (const L &lhs, const R &rhs)
 Tests each broadcasted left element for ordering above or equal to the corresponding right element.
 
template<Array A, DType Scalar>
auto equal (const A &lhs, const Scalar &rhs)
 Compares every array element for equality with a right-hand scalar.
 
template<DType Scalar, Array A>
auto equal (const Scalar &lhs, const A &rhs)
 Compares a left-hand scalar for equality with every array element.
 
template<Array A, DType Scalar>
auto not_equal (const A &lhs, const Scalar &rhs)
 Compares every array element for inequality with a right-hand scalar.
 
template<DType Scalar, Array A>
auto not_equal (const Scalar &lhs, const A &rhs)
 Compares a left-hand scalar for inequality with every array element.
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto less (const A &lhs, const Scalar &rhs)
 Tests each array element for strict ordering below a right-hand scalar.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto less (const Scalar &lhs, const A &rhs)
 Tests a left-hand scalar for strict ordering below each array element.
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto less_equal (const A &lhs, const Scalar &rhs)
 Tests each array element for ordering below or equal to a scalar.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto less_equal (const Scalar &lhs, const A &rhs)
 Tests a scalar for ordering below or equal to each array element.
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto greater (const A &lhs, const Scalar &rhs)
 Tests each array element for strict ordering above a right-hand scalar.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto greater (const Scalar &lhs, const A &rhs)
 Tests a left-hand scalar for strict ordering above each array element.
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto greater_equal (const A &lhs, const Scalar &rhs)
 Tests each array element for ordering above or equal to a scalar.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto greater_equal (const Scalar &lhs, const A &rhs)
 Tests a scalar for ordering above or equal to each array element.
 
template<Array L, Array R>
auto operator== (const L &lhs, const R &rhs)
 Element-wise array equality shorthand for equal().
 
template<Array L, Array R>
auto operator!= (const L &lhs, const R &rhs)
 Element-wise array inequality shorthand for not_equal().
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator< (const L &lhs, const R &rhs)
 Element-wise array less-than shorthand for less().
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator<= (const L &lhs, const R &rhs)
 Element-wise array less-than-or-equal shorthand for less_equal().
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator> (const L &lhs, const R &rhs)
 Element-wise array greater-than shorthand for greater().
 
template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator>= (const L &lhs, const R &rhs)
 Element-wise array greater-than-or-equal shorthand for greater_equal().
 
template<Array A, DType Scalar>
auto operator== (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar equality shorthand for equal().
 
template<DType Scalar, Array A>
auto operator== (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array equality shorthand for equal().
 
template<Array A, DType Scalar>
auto operator!= (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar inequality shorthand for not_equal().
 
template<DType Scalar, Array A>
auto operator!= (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array inequality shorthand for not_equal().
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator< (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar less-than shorthand for less().
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator< (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array less-than shorthand for less().
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator<= (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar less-than-or-equal shorthand.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator<= (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array less-than-or-equal shorthand.
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator> (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar greater-than shorthand for greater().
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator> (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array greater-than shorthand for greater().
 
template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator>= (const A &lhs, const Scalar &rhs)
 Element-wise array-to-scalar greater-than-or-equal shorthand.
 
template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator>= (const Scalar &lhs, const A &rhs)
 Element-wise scalar-to-array greater-than-or-equal shorthand.
 

Detailed Description

Element-wise boolean comparisons with broadcasting.

Operations that allocate results require owning-container result trait specializations. Element operators receive the original operand types; the result is converted afterward. Native C++ arithmetic and conversion rules apply, including representability requirements. Allocation failures propagate.

Definition in file Comparison.hpp.

Function Documentation

◆ array_equal()

template<Array L, Array R>
bool stratax::core::comparison_detail::array_equal ( const L &  lhs,
const R &  rhs 
)

Tests whether two arrays have identical shapes and element values.

Returns
true if the shapes and every corresponding value are equal.
Invariant
Both arrays remain unchanged.
Complexity
O(r + n) for owning arrays, O((n + 1) * r) for views, where r is rank and n is size.

Definition at line 143 of file Comparison.hpp.

◆ comparison_op()

template<Array L, Array R, typename Op >
auto stratax::core::comparison_detail::comparison_op ( const L &  lhs,
const R &  rhs,
Op  op 
)

Applies an element-wise comparison to two broadcast-compatible arrays.

Template Parameters
LLeft Stratax array type.
RRight Stratax array type.
OpBinary comparison callable.
Parameters
lhsLeft array operand.
rhsRight array operand.
opComparison applied to each broadcasted element pair.
Returns
Owning boolean array whose container type is the promotion of lhs and rhs and whose shape is their common broadcasted shape.
Invariant
The operands remain unchanged and the result always has boolean dtype.
Exceptions
Exceptions::BroadcastErrorIf shapes are incompatible or an empty operand would supply values to a nonempty result.
Complexity
O((n + 1) * r), where n is the result size and r is its rank.

Definition at line 36 of file Comparison.hpp.

◆ comparison_scalar_op() [1/2]

template<Array A, DType Scalar, typename Op >
auto stratax::core::comparison_detail::comparison_scalar_op ( const A &  lhs,
const Scalar &  rhs,
Op  op 
)

Compares every array element with a scalar on the right.

Returns
Owning boolean array with lhs's container type and shape.
Invariant
The operands remain unchanged and the result always has boolean dtype.
Complexity
O(lhs.size()).

Definition at line 81 of file Comparison.hpp.

◆ comparison_scalar_op() [2/2]

template<DType Scalar, Array A, typename Op >
auto stratax::core::comparison_detail::comparison_scalar_op ( const Scalar &  lhs,
const A &  rhs,
Op  op 
)

Compares a scalar on the left with every array element.

Returns
Owning boolean array with rhs's container type and shape.
Invariant
The operands remain unchanged and the result always has boolean dtype.
Complexity
O(rhs.size()).

Definition at line 112 of file Comparison.hpp.

◆ equal() [1/3]

template<Array A, DType Scalar>
auto equal ( const A &  lhs,
const Scalar &  rhs 
)

Compares every array element for equality with a right-hand scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 270 of file Comparison.hpp.

◆ equal() [2/3]

template<Array L, Array R>
auto equal ( const L &  lhs,
const R &  rhs 
)

Compares two arrays for element-wise equality with broadcasting.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 173 of file Comparison.hpp.

◆ equal() [3/3]

template<DType Scalar, Array A>
auto equal ( const Scalar &  lhs,
const A &  rhs 
)

Compares a left-hand scalar for equality with every array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 282 of file Comparison.hpp.

◆ greater() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto greater ( const A &  lhs,
const Scalar &  rhs 
)

Tests each array element for strict ordering above a right-hand scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 371 of file Comparison.hpp.

◆ greater() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto greater ( const L &  lhs,
const R &  rhs 
)

Tests each broadcasted left element for strict ordering above the corresponding right element.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 240 of file Comparison.hpp.

◆ greater() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto greater ( const Scalar &  lhs,
const A &  rhs 
)

Tests a left-hand scalar for strict ordering above each array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 384 of file Comparison.hpp.

◆ greater_equal() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto greater_equal ( const A &  lhs,
const Scalar &  rhs 
)

Tests each array element for ordering above or equal to a scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 397 of file Comparison.hpp.

◆ greater_equal() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto greater_equal ( const L &  lhs,
const R &  rhs 
)

Tests each broadcasted left element for ordering above or equal to the corresponding right element.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 258 of file Comparison.hpp.

◆ greater_equal() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto greater_equal ( const Scalar &  lhs,
const A &  rhs 
)

Tests a scalar for ordering above or equal to each array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 410 of file Comparison.hpp.

◆ less() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto less ( const A &  lhs,
const Scalar &  rhs 
)

Tests each array element for strict ordering below a right-hand scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 319 of file Comparison.hpp.

◆ less() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto less ( const L &  lhs,
const R &  rhs 
)

Tests each broadcasted left element for strict ordering below the corresponding right element.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 204 of file Comparison.hpp.

◆ less() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto less ( const Scalar &  lhs,
const A &  rhs 
)

Tests a left-hand scalar for strict ordering below each array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 332 of file Comparison.hpp.

◆ less_equal() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto less_equal ( const A &  lhs,
const Scalar &  rhs 
)

Tests each array element for ordering below or equal to a scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 345 of file Comparison.hpp.

◆ less_equal() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto less_equal ( const L &  lhs,
const R &  rhs 
)

Tests each broadcasted left element for ordering below or equal to the corresponding right element.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 222 of file Comparison.hpp.

◆ less_equal() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto less_equal ( const Scalar &  lhs,
const A &  rhs 
)

Tests a scalar for ordering below or equal to each array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 358 of file Comparison.hpp.

◆ not_equal() [1/3]

template<Array A, DType Scalar>
auto not_equal ( const A &  lhs,
const Scalar &  rhs 
)

Compares every array element for inequality with a right-hand scalar.

Returns
Owning boolean array with the same container and shape as lhs.
Complexity
O(lhs.size()).

Definition at line 294 of file Comparison.hpp.

◆ not_equal() [2/3]

template<Array L, Array R>
auto not_equal ( const L &  lhs,
const R &  rhs 
)

Compares two arrays for element-wise inequality with broadcasting.

Returns
Owning boolean array with the common broadcasted shape.
Exceptions
Exceptions::BroadcastErrorIf broadcasting is impossible, including an empty operand supplying a nonempty result.
Complexity
O((n + 1) * r), where n is result size and r is result rank.

Definition at line 186 of file Comparison.hpp.

◆ not_equal() [3/3]

template<DType Scalar, Array A>
auto not_equal ( const Scalar &  lhs,
const A &  rhs 
)

Compares a left-hand scalar for inequality with every array element.

Returns
Owning boolean array with the same container and shape as rhs.
Complexity
O(rhs.size()).

Definition at line 306 of file Comparison.hpp.

◆ operator!=() [1/3]

template<Array A, DType Scalar>
auto operator!= ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar inequality shorthand for not_equal().

Complexity
O(lhs.size()).

Definition at line 517 of file Comparison.hpp.

◆ operator!=() [2/3]

template<Array L, Array R>
auto operator!= ( const L &  lhs,
const R &  rhs 
)

Element-wise array inequality shorthand for not_equal().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 431 of file Comparison.hpp.

◆ operator!=() [3/3]

template<DType Scalar, Array A>
auto operator!= ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array inequality shorthand for not_equal().

Complexity
O(rhs.size()).

Definition at line 527 of file Comparison.hpp.

◆ operator<() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator< ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar less-than shorthand for less().

Complexity
O(lhs.size()).

Definition at line 538 of file Comparison.hpp.

◆ operator<() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator< ( const L &  lhs,
const R &  rhs 
)

Element-wise array less-than shorthand for less().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 445 of file Comparison.hpp.

◆ operator<() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator< ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array less-than shorthand for less().

Complexity
O(rhs.size()).

Definition at line 549 of file Comparison.hpp.

◆ operator<=() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator<= ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar less-than-or-equal shorthand.

Complexity
O(lhs.size()).

Definition at line 560 of file Comparison.hpp.

◆ operator<=() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator<= ( const L &  lhs,
const R &  rhs 
)

Element-wise array less-than-or-equal shorthand for less_equal().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 459 of file Comparison.hpp.

◆ operator<=() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator<= ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array less-than-or-equal shorthand.

Complexity
O(rhs.size()).

Definition at line 571 of file Comparison.hpp.

◆ operator==() [1/3]

template<Array A, DType Scalar>
auto operator== ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar equality shorthand for equal().

Complexity
O(lhs.size()).

Definition at line 497 of file Comparison.hpp.

◆ operator==() [2/3]

template<Array L, Array R>
auto operator== ( const L &  lhs,
const R &  rhs 
)

Element-wise array equality shorthand for equal().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 421 of file Comparison.hpp.

◆ operator==() [3/3]

template<DType Scalar, Array A>
auto operator== ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array equality shorthand for equal().

Complexity
O(rhs.size()).

Definition at line 507 of file Comparison.hpp.

◆ operator>() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator> ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar greater-than shorthand for greater().

Complexity
O(lhs.size()).

Definition at line 582 of file Comparison.hpp.

◆ operator>() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator> ( const L &  lhs,
const R &  rhs 
)

Element-wise array greater-than shorthand for greater().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 473 of file Comparison.hpp.

◆ operator>() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator> ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array greater-than shorthand for greater().

Complexity
O(rhs.size()).

Definition at line 593 of file Comparison.hpp.

◆ operator>=() [1/3]

template<Array A, Ordered Scalar>
requires Ordered<typename A::value_type>
auto operator>= ( const A &  lhs,
const Scalar &  rhs 
)

Element-wise array-to-scalar greater-than-or-equal shorthand.

Complexity
O(lhs.size()).

Definition at line 604 of file Comparison.hpp.

◆ operator>=() [2/3]

template<Array L, Array R>
requires ( Ordered<typename L::value_type> && Ordered<typename R::value_type> )
auto operator>= ( const L &  lhs,
const R &  rhs 
)

Element-wise array greater-than-or-equal shorthand for greater_equal().

Complexity
O((n + 1) * r), including broadcast-index mapping.

Definition at line 487 of file Comparison.hpp.

◆ operator>=() [3/3]

template<Ordered Scalar, Array A>
requires Ordered<typename A::value_type>
auto operator>= ( const Scalar &  lhs,
const A &  rhs 
)

Element-wise scalar-to-array greater-than-or-equal shorthand.

Complexity
O(rhs.size()).

Definition at line 615 of file Comparison.hpp.