mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-10 07:28:15 -05:00
Add linalg_det and test for torch backend (#11405)
* add linalg_det and test * space --------- Co-authored-by: chenyu <chenyu@fastmail.com>
This commit is contained in:
@@ -128,6 +128,12 @@ def _linalg_eigh(self, UPLO: str = 'U'):
|
||||
w, v = torch.linalg.eigh(self.cpu(), UPLO=UPLO)
|
||||
return w.tiny(), v.tiny()
|
||||
|
||||
@torch.library.impl("aten::_linalg_det", "privateuseone")
|
||||
# TODO: move to tinygrad
|
||||
def _linalg_det(self: torch.Tensor):
|
||||
result = aten._linalg_det(self.cpu())
|
||||
return result[0].tiny(), result[1].tiny(), result[2].tiny()
|
||||
|
||||
def upsample_backward(grad_out, output_size, input_size, *args, f=None): return f(grad_out.cpu(), output_size, input_size, *args).tiny()
|
||||
|
||||
for i in [
|
||||
|
||||
@@ -198,6 +198,11 @@ class TestTorchBackend(unittest.TestCase):
|
||||
recon = (v @ torch.diag(w) @ v.T).cpu().numpy()
|
||||
np.testing.assert_allclose(recon, a.cpu().numpy(), atol=1e-6)
|
||||
|
||||
def test_linalg_det(self):
|
||||
a = torch.diag(torch.tensor([1,2,3,4,5], dtype = torch.float32, device=device))
|
||||
b = torch.linalg.det(a)
|
||||
np.testing.assert_equal(b.cpu().numpy(), 120.0)
|
||||
|
||||
def test_scalar_assign(self):
|
||||
a = torch.tensor([1, 2, 3], device=device)
|
||||
a[1] = 4
|
||||
|
||||
Reference in New Issue
Block a user