Skip to main content

coeus_ops/binary/
comparison.rs

1// ── Binary comparison ops (mask) ──
2
3use super::kernel::elementwise_binary;
4use crate::backend_ops::{BinaryOp, ElementwiseOps};
5use coeus_core::Scalar;
6use coeus_tensor::Tensor;
7
8/// Element-wise equality comparison mask.
9#[inline]
10pub fn eq<T: Scalar, B: ElementwiseOps<T>>(
11    a: &Tensor<T, B>,
12    b: &Tensor<T, B>,
13    backend: &B,
14) -> Result<Tensor<T, B>, B::Error> {
15    elementwise_binary(a, b, backend, BinaryOp::Eq)
16}
17
18/// Element-wise inequality comparison mask.
19#[inline]
20pub fn ne<T: Scalar, B: ElementwiseOps<T>>(
21    a: &Tensor<T, B>,
22    b: &Tensor<T, B>,
23    backend: &B,
24) -> Result<Tensor<T, B>, B::Error> {
25    elementwise_binary(a, b, backend, BinaryOp::Ne)
26}
27
28/// Element-wise less-than comparison mask.
29#[inline]
30pub fn lt<T: Scalar, B: ElementwiseOps<T>>(
31    a: &Tensor<T, B>,
32    b: &Tensor<T, B>,
33    backend: &B,
34) -> Result<Tensor<T, B>, B::Error> {
35    elementwise_binary(a, b, backend, BinaryOp::Lt)
36}
37
38/// Element-wise greater-than comparison mask.
39#[inline]
40pub fn gt<T: Scalar, B: ElementwiseOps<T>>(
41    a: &Tensor<T, B>,
42    b: &Tensor<T, B>,
43    backend: &B,
44) -> Result<Tensor<T, B>, B::Error> {
45    elementwise_binary(a, b, backend, BinaryOp::Gt)
46}
47
48/// Element-wise less-than-or-equal comparison mask.
49#[inline]
50pub fn le<T: Scalar, B: ElementwiseOps<T>>(
51    a: &Tensor<T, B>,
52    b: &Tensor<T, B>,
53    backend: &B,
54) -> Result<Tensor<T, B>, B::Error> {
55    elementwise_binary(a, b, backend, BinaryOp::Le)
56}
57
58/// Element-wise greater-than-or-equal comparison mask.
59#[inline]
60pub fn ge<T: Scalar, B: ElementwiseOps<T>>(
61    a: &Tensor<T, B>,
62    b: &Tensor<T, B>,
63    backend: &B,
64) -> Result<Tensor<T, B>, B::Error> {
65    elementwise_binary(a, b, backend, BinaryOp::Ge)
66}