Skip to content
fn

equal_op

→TensorImplPtr
int equal_op(const int & a, const int & b)

Python wrappers

Public Python APIs implemented by this engine symbol.

Element-wise equality comparison.

Computes out[i] = (a[i] == b[i]) for every element and returns the result as a Bool tensor. The comparison is exact, so for floating-point inputs it follows IEEE 754 equality (NaN == NaN is false).

Non-differentiable: the comparison function has zero gradient almost everywhere and undefined gradient on the decision boundary, so no autograd node is registered and the output never carries grad.

Math

out[i]=1 ⁣[a[i]=b[i]]. \mathrm{out}[i] = \mathbf{1}\!\left[a[i] = b[i]\right].

References

NumPy numpy.equal.

See Also

not_equal_op, less_op, greater_op

Parameters

a, bTensorImplPtr
Operands. Must have identical shape, dtype, and device — this op does not broadcast.

Returns

TensorImplPtr

Bool tensor with the same shape as a and b.

Raises

LucidError
If the operand shapes, dtypes, or devices differ.

Notes

  • Output dtype is always Bool regardless of input dtype.
  • No broadcasting — callers must align shapes upstream.

Examples

auto a = tensor({1, 2, 3});
    auto b = tensor({1, 0, 3});
    auto m = equal_op(a, b);  // Bool[true, false, true]