MCPcopy
hub / github.com/tinygrad/tinygrad / test_nonzero_size

Method test_nonzero_size

test/backend/test_ops.py:3360–3367  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3358
3359 @unittest.skipIf(COMPILE_ONLY, "test requires runtime")
3360 def test_nonzero_size(self):
3361 np.testing.assert_equal(Tensor([1, 0, 2, 0, 3]).nonzero(size=3).numpy(), [[0], [2], [4]])
3362 np.testing.assert_equal(Tensor([1, 0, 2, 0, 3]).nonzero(size=5, fill_value=-1).numpy(), [[0], [2], [4], [-1], [-1]])
3363 np.testing.assert_equal(Tensor([[1, 0], [0, 2]]).nonzero(size=2).numpy(), [[0, 0], [1, 1]])
3364 self.assertEqual(Tensor(5).nonzero(size=4).shape, (4, 0))
3365 np.testing.assert_equal(Tensor([], dtype=dtypes.int32).nonzero(size=3, fill_value=-1).numpy(), [[-1], [-1], [-1]])
3366 # fill_value must not promote dtype to float
3367 self.assertEqual(Tensor([1, 0]).nonzero(size=3, fill_value=-1.5).dtype, dtypes.default_int)
3368
3369 def test_cast(self):
3370 helper_test_op([(3, 3)], lambda x: x.float())

Callers

nothing calls this directly

Calls 4

TensorClass · 0.90
assert_equalMethod · 0.80
nonzeroMethod · 0.80
numpyMethod · 0.45

Tested by

no test coverage detected