From 2ff8669c3bc91d3970dbca8fe753693ca6053781 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 21 Jul 2025 12:07:38 +0200 Subject: [PATCH 1/4] Fix error when ndarray creates with a buffer as data --- dpnp/memory/_memory.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpnp/memory/_memory.py b/dpnp/memory/_memory.py index c1f60ec14cc4..09edcda2aa2f 100644 --- a/dpnp/memory/_memory.py +++ b/dpnp/memory/_memory.py @@ -95,6 +95,9 @@ def create_data(x): ) usm_data = x.usm_data + if isinstance(usm_data, tuple(dispatch.keys())): + return usm_data + cls = dispatch.get(type(usm_data), None) if cls: data = cls(usm_data) From 783d2649c81851afe46b67b90ba7c047944bbb6e Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 21 Jul 2025 12:08:11 +0200 Subject: [PATCH 2/4] Add test to cover the new handling --- dpnp/tests/test_memory.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpnp/tests/test_memory.py b/dpnp/tests/test_memory.py index 30afe5fa908c..5c7c1cad522a 100644 --- a/dpnp/tests/test_memory.py +++ b/dpnp/tests/test_memory.py @@ -26,3 +26,8 @@ def test_wrong_usm_data(self): with pytest.raises(TypeError): dpm.create_data(d) + + def test_ndarray_from_data(self): + a = dpnp.empty(5) + b = dpnp.ndarray(a.shape, buffer=a.data) + assert b.data is a.data From 43b63fe31d3787ccd8d3b9d158fda52730ec4e4f Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 21 Jul 2025 12:14:51 +0200 Subject: [PATCH 3/4] Add PR to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97c45c670ba8..fbbd3323993f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated the math formulas in summary of `dpnp.matvec` and `dpnp.vecmat` to correct a typo [#2503](https://github.com/IntelPython/dpnp/pull/2503) * Avoided negating unsigned integers in ceil division used in `dpnp.resize` implementation [#2508](https://github.com/IntelPython/dpnp/pull/2508) * Fixed `dpnp.unique` with 1d input array and `axis=0`, `equal_nan=True` keywords passed where the produced result doesn't collapse the NaNs [#2530](https://github.com/IntelPython/dpnp/pull/2530) +* Resolved issue when `dpnp.ndarray` constructor is called with `dpnp.ndarray.data` as `buffer` keyword [#2533](https://github.com/IntelPython/dpnp/pull/2533) ### Security From d507e2010ca87752107119b943818d1eed1f771d Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 21 Jul 2025 13:26:05 +0200 Subject: [PATCH 4/4] Improve test check and fix typo in type check --- dpnp/memory/_memory.py | 2 +- dpnp/tests/test_memory.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/memory/_memory.py b/dpnp/memory/_memory.py index 09edcda2aa2f..c3f0984c52e7 100644 --- a/dpnp/memory/_memory.py +++ b/dpnp/memory/_memory.py @@ -95,7 +95,7 @@ def create_data(x): ) usm_data = x.usm_data - if isinstance(usm_data, tuple(dispatch.keys())): + if isinstance(usm_data, tuple(dispatch.values())): return usm_data cls = dispatch.get(type(usm_data), None) diff --git a/dpnp/tests/test_memory.py b/dpnp/tests/test_memory.py index 5c7c1cad522a..ce9c7e60f030 100644 --- a/dpnp/tests/test_memory.py +++ b/dpnp/tests/test_memory.py @@ -30,4 +30,4 @@ def test_wrong_usm_data(self): def test_ndarray_from_data(self): a = dpnp.empty(5) b = dpnp.ndarray(a.shape, buffer=a.data) - assert b.data is a.data + assert b.data.ptr == a.data.ptr