equal¶
- nvtripy.equal(input: Tensor, other: Tensor) bool [source]¶
Returns
True
ifinput
andother
have the same shape and elements.Caution
This function cannot be used in a compiled function or
nvtripy.Module
because it depends on evaluating its inputs, which is not allowed during compilation.- Parameters:
- Returns:
True
if the tensors have the same shape and elements andFalse
otherwise.- Return type:
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, 1]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[1, 1]], 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, 1]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[1, 1], [1, 1]], 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, 1]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[0, 0]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> is_equal False