(self, f:Callable, jf:Callable|None=None)
| 12 | self.assertAlmostEqual(x, y, places=5) |
| 13 | |
| 14 | def _test_one_input_function(self, f:Callable, jf:Callable|None=None): |
| 15 | if jf is None: jf = f |
| 16 | x = UOp.variable('x', -math.inf, math.inf, dtype=dtypes.float) |
| 17 | gx = compute_gradient(f(x), UOp.const(dtypes.float, 1.0), set([x]))[x] |
| 18 | |
| 19 | for val in [-5., -2.0, 0.0, 2.0, 5.]: |
| 20 | tg_out = gx.substitute({x: x.const_like(val)}).ssimplify() |
| 21 | tx = torch.tensor([val], dtype=torch.float, requires_grad=True) |
| 22 | torch_out = torch.autograd.grad(jf(tx), tx)[0].item() |
| 23 | self._cmp_nan_okay(tg_out, torch_out) |
| 24 | |
| 25 | def _test_two_input_function(self, f:Callable, jf:Callable|None=None): |
| 26 | if jf is None: jf = f |
no test coverage detected