From c30f3fa9d7ed7813766d78abf0b0abdf139105db Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 26 Aug 2026 19:36:39 +0200 Subject: [PATCH 1/2] task: add ndmax keyword to dpnp.array (#3044) Align dpnp.array with NumPy 2.4.0, which added an ndmax keyword. The truncating behavior of ndmax produces object-dtype arrays, which USM arrays cannot represent, so ndmax is accepted only with its default value 0 and raises NotImplementedError otherwise. --- CHANGELOG.md | 1 + dpnp/dpnp_iface.py | 7 +++++++ dpnp/dpnp_iface_arraycreation.py | 4 +++- dpnp/tests/test_arraycreation.py | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97fd31e5a50..b479181763c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This release is compatible with NumPy 2.5. * Added `dpnp.tensor.broadcast_shapes` to align with the 2025.12 version of the Python array API [#3009](https://github.com/IntelPython/dpnp/pull/3009) * Added support for free-threaded Python builds [gh-3026](https://github.com/IntelPython/dpnp/pull/3026) * Added `dpnp.broadcast` class implementation [#2901](https://github.com/IntelPython/dpnp/pull/2901) +* Added the `ndmax` keyword to `dpnp.array` for compatibility with NumPy [#3044](https://github.com/IntelPython/dpnp/pull/3044) ### Changed diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index d36aa06da99..2561e24b4a0 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -196,6 +196,7 @@ def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): def check_limitations( subok=False, + ndmax=0, like=None, initial=None, where=True, @@ -207,6 +208,7 @@ def check_limitations( Parameter `subok` for array creation functions is only supported with default value ``False``. + Parameter `ndmax` is only supported with default value ``0``. Parameter `like` is only supported with default value ``None``. Parameter `initial` is only supported with default value ``None``. Parameter `where` is only supported with default value ``True``. @@ -231,6 +233,11 @@ def check_limitations( "Keyword argument `subok` is supported only with " f"default value ``False``, but got {subok}." ) + if ndmax != 0: + raise NotImplementedError( + "Keyword argument `ndmax` is supported only with " + f"default value ``0``, but got {ndmax}." + ) if initial is not None: raise NotImplementedError( "Keyword argument `initial` is only supported with " diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 98d9945be33..ae68e8b0fd1 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -261,6 +261,7 @@ def array( order="K", subok=False, ndmin=0, + ndmax=0, like=None, device=None, usm_type=None, @@ -329,6 +330,7 @@ def array( Limitations ----------- Parameter `subok` is supported only with default value ``False``. + Parameter `ndmax` is supported only with default value ``0``. Parameter `like` is supported only with default value ``None``. Otherwise, the function raises ``NotImplementedError`` exception. @@ -396,7 +398,7 @@ def array( """ - dpnp.check_limitations(subok=subok, like=like) + dpnp.check_limitations(subok=subok, ndmax=ndmax, like=like) if not isinstance(ndmin, (int, dpnp.integer)): raise TypeError(f"`ndmin` should be an integer, got {type(ndmin)}") diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index 1dd8e905577..5b2c298408d 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -55,6 +55,16 @@ def test_ndmin_order(self, x, order, ndmin): assert a.flags.f_contiguous == ia.flags.f_contiguous assert_array_equal(ia, a) + def test_ndmax_default(self): + x = [[1, 2, 3], [4, 5, 6]] + a = numpy.array(x, ndmax=0) + ia = dpnp.array(x, ndmax=0) + assert_array_equal(ia, a) + + @pytest.mark.parametrize("ndmax", [1, 2, 3]) + def test_ndmax_unsupported(self, ndmax): + assert_raises(NotImplementedError, dpnp.array, [[1, 2, 3]], ndmax=ndmax) + def test_error(self): x = numpy.ones((3, 4)) assert_raises(TypeError, dpnp.array, x, ndmin=3.0) From e16af1ca2abbae68884ee0aca177c5b4a4f12f04 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 26 Aug 2026 23:00:20 +0200 Subject: [PATCH 2/2] task: fix ndmax test baseline for NumPy compatibility An explicit ndmax=0 makes NumPy cap the result at zero dimensions and raise, so it cannot serve as a test baseline. Compare dpnp's no-op ndmax=0 against NumPy's no-op (ndmax >= ndim) and gate the test on numpy>=2.4, where the ndmax keyword is available. --- dpnp/tests/test_arraycreation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index 5b2c298408d..cfe6eee778d 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -55,9 +55,13 @@ def test_ndmin_order(self, x, order, ndmin): assert a.flags.f_contiguous == ia.flags.f_contiguous assert_array_equal(ia, a) + @testing.with_requires("numpy>=2.4") def test_ndmax_default(self): + # dpnp supports only the default `ndmax=0`, treating it as a no-op; + # the NumPy no-op is `ndmax >= ndim` (an explicit `ndmax=0` caps the + # result at zero dimensions and raises) x = [[1, 2, 3], [4, 5, 6]] - a = numpy.array(x, ndmax=0) + a = numpy.array(x, ndmax=numpy.ndim(x)) ia = dpnp.array(x, ndmax=0) assert_array_equal(ia, a)