mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-25 18:11:15 +08:00
make python array SupportsAbs conform (like numpy) (#624)
This commit is contained in:
parent
9852af1a19
commit
4fd2fb84a6
@ -1110,6 +1110,7 @@ void init_array(py::module_& m) {
|
|||||||
py::kw_only(),
|
py::kw_only(),
|
||||||
"stream"_a = none,
|
"stream"_a = none,
|
||||||
"See :func:`abs`.")
|
"See :func:`abs`.")
|
||||||
|
.def("__abs__", &mlx::core::abs, "See :func:`abs`.")
|
||||||
.def(
|
.def(
|
||||||
"square",
|
"square",
|
||||||
&square,
|
&square,
|
||||||
|
@ -696,6 +696,8 @@ class TestOps(mlx_tests.MLXTestCase):
|
|||||||
expected = np.abs(a, dtype=np.float32)
|
expected = np.abs(a, dtype=np.float32)
|
||||||
self.assertTrue(np.allclose(result, expected))
|
self.assertTrue(np.allclose(result, expected))
|
||||||
|
|
||||||
|
self.assertTrue(np.allclose(a.abs(), abs(a)))
|
||||||
|
|
||||||
def test_negative(self):
|
def test_negative(self):
|
||||||
a = mx.array([-1.0, 1.0, -2.0, 3.0])
|
a = mx.array([-1.0, 1.0, -2.0, 3.0])
|
||||||
result = mx.negative(a)
|
result = mx.negative(a)
|
||||||
|
Loading…
Reference in New Issue
Block a user