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:
kevvz
2025-07-30 19:04:44 -07:00
committed by GitHub
parent cba3655de5
commit c3cfcb50cb
2 changed files with 11 additions and 0 deletions

View File

@@ -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 [

View File

@@ -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