Skip to content

Add asnumpy() method for dpnp_array #1248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,22 @@ def __setitem__(self, key, val):
# '__setstate__',
# '__sizeof__',


def __str__(self):
""" Output values from the array to standard output
"""
Output values from the array to standard output.

Example:
[[ 136. 136. 136.]
[ 272. 272. 272.]
[ 408. 408. 408.]]
Examples
--------
>>> print(a)
[[ 136. 136. 136.]
[ 272. 272. 272.]
[ 408. 408. 408.]]

"""

return str(dpnp.asnumpy(self._array_obj))
return str(self.asnumpy())


def __sub__(self, other):
return dpnp.subtract(self, other)
Expand Down Expand Up @@ -425,6 +430,20 @@ def argsort(self, axis=-1, kind=None, order=None):
"""
return dpnp.argsort(self, axis, kind, order)


def asnumpy(self):
"""
Copy content of the array into :class:`numpy.ndarray` instance of the same shape and data type.

Returns
-------
An instance of :class:`numpy.ndarray` populated with the array content.

"""

return dpt.asnumpy(self._array_obj)


def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True):
"""Copy the array with data type casting.

Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def asnumpy(input, order='C'):

"""
if isinstance(input, dpnp_array):
return dpt.asnumpy(input.get_array())
return input.asnumpy()

if isinstance(input, dpt.usm_ndarray):
return dpt.asnumpy(input)
Expand Down