mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-12 07:18:52 +08:00
fix pinv (#2110)
This commit is contained in:
@@ -197,6 +197,13 @@ void init_array(nb::module_& m) {
|
||||
"max",
|
||||
&mx::finfo::max,
|
||||
R"pbdoc(The largest representable number.)pbdoc")
|
||||
.def_ro(
|
||||
"eps",
|
||||
&mx::finfo::eps,
|
||||
R"pbdoc(
|
||||
The difference between 1.0 and the next smallest
|
||||
representable number larger than 1.0.
|
||||
)pbdoc")
|
||||
.def_ro("dtype", &mx::finfo::dtype, R"pbdoc(The :obj:`Dtype`.)pbdoc")
|
||||
.def("__repr__", [](const mx::finfo& f) {
|
||||
std::ostringstream os;
|
||||
|
||||
@@ -103,10 +103,12 @@ class TestDtypes(mlx_tests.MLXTestCase):
|
||||
|
||||
self.assertEqual(mx.finfo(mx.float32).min, np.finfo(np.float32).min)
|
||||
self.assertEqual(mx.finfo(mx.float32).max, np.finfo(np.float32).max)
|
||||
self.assertEqual(mx.finfo(mx.float32).eps, np.finfo(np.float32).eps)
|
||||
self.assertEqual(mx.finfo(mx.float32).dtype, mx.float32)
|
||||
|
||||
self.assertEqual(mx.finfo(mx.float16).min, np.finfo(np.float16).min)
|
||||
self.assertEqual(mx.finfo(mx.float16).max, np.finfo(np.float16).max)
|
||||
self.assertEqual(mx.finfo(mx.float16).eps, np.finfo(np.float16).eps)
|
||||
self.assertEqual(mx.finfo(mx.float16).dtype, mx.float16)
|
||||
|
||||
def test_iinfo(self):
|
||||
|
||||
@@ -232,6 +232,11 @@ class TestLinalg(mlx_tests.MLXTestCase):
|
||||
for M, M_plus in zip(AB, pinvs):
|
||||
self.assertTrue(mx.allclose(M @ M_plus @ M, M, rtol=0, atol=1e-3))
|
||||
|
||||
# Test singular matrix
|
||||
A = mx.array([[4.0, 1.0], [4.0, 1.0]])
|
||||
A_plus = mx.linalg.pinv(A, stream=mx.cpu)
|
||||
self.assertTrue(mx.allclose(A @ A_plus @ A, A))
|
||||
|
||||
def test_cholesky_inv(self):
|
||||
mx.random.seed(7)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user