MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / test_grad_implicit

Method test_grad_implicit

test/unit/test_function.py:103–111  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

101 np.testing.assert_allclose(b.grad.numpy(), na.T @ nb + na @ nb)
102
103 def test_grad_implicit(self):
104 w = Tensor([1., 2., 3.])
105 w.realize() # TODO: this is required
106 @function(allow_implicit=True)
107 def f(x:Tensor) -> Tensor: return x * w
108
109 x = Tensor([4., 5., 6.])
110 f(x).sum().backward()
111 np.testing.assert_allclose(w.grad.numpy(), [4., 5., 6.])
112
113 def test_symbolic_index(self):
114 table = Tensor([10,20,30,40]).contiguous().realize()

Callers

nothing calls this directly

Calls 6

realizeMethod · 0.95
TensorClass · 0.90
sumMethod · 0.80
fFunction · 0.50
backwardMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected