Allow non-square lu (#1889)

This commit is contained in:
Awni Hannun
2025-02-20 08:13:23 -08:00
committed by GitHub
parent c86422bdd4
commit bbda0fdbdb
3 changed files with 34 additions and 9 deletions

View File

@@ -358,6 +358,15 @@ class TestLinalg(mlx_tests.MLXTestCase):
L = mx.take_along_axis(L, P[..., None], axis=-2)
self.assertTrue(mx.allclose(L @ U, a))
# Test non-square matrix
a = mx.array([[3.0, 1.0, 2.0], [1.0, 8.0, 6.0]])
P, L, U = mx.linalg.lu(a, stream=mx.cpu)
self.assertTrue(mx.allclose(L[P, :] @ U, a))
a = mx.array([[3.0, 1.0], [1.0, 8.0], [9.0, 2.0]])
P, L, U = mx.linalg.lu(a, stream=mx.cpu)
self.assertTrue(mx.allclose(L[P, :] @ U, a))
def test_lu_factor(self):
mx.random.seed(7)