From 9a8bbf4b50de24ecae6741a4435204e2c3b2c388 Mon Sep 17 00:00:00 2001 From: blanky Date: Fri, 11 Sep 2026 03:18:52 +0530 Subject: [PATCH] added pos support --- python/src/array.cpp | 1 + python/tests/test_array.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python/src/array.cpp b/python/src/array.cpp index 37d420b14e..8dd1a112e2 100644 --- a/python/src/array.cpp +++ b/python/src/array.cpp @@ -806,6 +806,7 @@ void init_array(nb::module_& m) { }, "other"_a) .def("__neg__", [](const mx::array& a) { return -a; }) + .def("__pos__", [](const mx::array& a) { return mx::copy(a); }) .def("__bool__", [](mx::array& a) { return nb::bool_(to_scalar(a)); }) .def( "__repr__", diff --git a/python/tests/test_array.py b/python/tests/test_array.py index ab79b5563b..9c6fa3711b 100644 --- a/python/tests/test_array.py +++ b/python/tests/test_array.py @@ -1041,11 +1041,14 @@ def test_array_comparison(self): self.assertEqual((a > 1).tolist(), [False, False, True]) self.assertEqual((a >= 1).tolist(), [False, True, True]) - def test_array_neg(self): + def test_array_unary_ops(self): a = mx.array([-1.0, 4.0, 0.0]) self.assertEqual((-a).tolist(), [1.0, -4.0, 0.0]) + self.assertEqual((+a).tolist(), [-1.0, 4.0, 0.0]) + assert +a is not a + def test_array_type_cast(self): a = mx.array([0.1, 2.3, -1.3]) b = [0, 2, -1]