equal

nvtripy.equal(input: Tensor, other: Tensor) bool[source]

Returns True if input and other have the same shape and elements.

Parameters:
  • input (Tensor) – [dtype=T1] First tensor to compare.

  • other (Tensor) – [dtype=T1] Second tensor to compare.

Returns:

True if the tensors have the same shape and elements and False otherwise.

Return type:

bool

TYPE CONSTRAINTS:
Example: Identical tensors
1a = tp.ones((1, 2), dtype=tp.float32)
2b = tp.ones((1, 2), dtype=tp.float32)
3
4is_equal = tp.equal(a, b)
Local Variables
>>> a
tensor(
    [[1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 2))

>>> b
tensor(
    [[1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 2))

>>> is_equal
True
Example: Different shapes
1a = tp.ones((1, 2), dtype=tp.float32)
2b = tp.ones((2, 2), dtype=tp.float32)
3
4is_equal = tp.equal(a, b)
Local Variables
>>> a
tensor(
    [[1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 2))

>>> b
tensor(
    [[1.0000, 1.0000],
     [1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(2, 2))

>>> is_equal
False
Example: Different elements
1a = tp.ones((1, 2), dtype=tp.float32)
2b = tp.zeros((1, 2), dtype=tp.float32)
3
4is_equal = tp.equal(a, b)
Local Variables
>>> a
tensor(
    [[1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 2))

>>> b
tensor(
    [[0.0000, 0.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 2))

>>> is_equal
False