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

Method test_with_custom_gradient

test/unit/test_gradient.py:21–25  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

19 self.assertListEqual(x.sum().gradient(w)[0].tolist(), [0.0, 0.0, 0.0])
20
21 def test_with_custom_gradient(self):
22 x = Tensor([1.0, 2.0, 3.0])
23 z = (x * x).sum()
24 dx = z.gradient(x, gradient=Tensor([3.0]))[0]
25 self.assertListEqual(dx.tolist(), [6.0, 12.0, 18.0])
26
27 def test_broadcast_gradient(self):
28 x = Tensor([[1.0], [2.0], [3.0]])

Callers

nothing calls this directly

Calls 4

TensorClass · 0.90
sumMethod · 0.80
gradientMethod · 0.80
tolistMethod · 0.45

Tested by

no test coverage detected