Skip to content

Commit 307fc66

Browse files
authored
Fix dpnp.ndarray constructor call with buffer passed as data property (#2533)
The PR closes gh-2532. In the faulty example the buffer was passed with `.data` of dpnp.ndarray. In that case there is no need to cast dpctl's `usm_data` to DPNP memory object.
1 parent 81870b7 commit 307fc66

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4343
* Updated the math formulas in summary of `dpnp.matvec` and `dpnp.vecmat` to correct a typo [#2503](https://github.com/IntelPython/dpnp/pull/2503)
4444
* Avoided negating unsigned integers in ceil division used in `dpnp.resize` implementation [#2508](https://github.com/IntelPython/dpnp/pull/2508)
4545
* 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)
46+
* Resolved issue when `dpnp.ndarray` constructor is called with `dpnp.ndarray.data` as `buffer` keyword [#2533](https://github.com/IntelPython/dpnp/pull/2533)
4647

4748
### Security
4849

dpnp/memory/_memory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def create_data(x):
9595
)
9696
usm_data = x.usm_data
9797

98+
if isinstance(usm_data, tuple(dispatch.values())):
99+
return usm_data
100+
98101
cls = dispatch.get(type(usm_data), None)
99102
if cls:
100103
data = cls(usm_data)

dpnp/tests/test_memory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ def test_wrong_usm_data(self):
2626

2727
with pytest.raises(TypeError):
2828
dpm.create_data(d)
29+
30+
def test_ndarray_from_data(self):
31+
a = dpnp.empty(5)
32+
b = dpnp.ndarray(a.shape, buffer=a.data)
33+
assert b.data.ptr == a.data.ptr

0 commit comments

Comments
 (0)