-
Notifications
You must be signed in to change notification settings - Fork 21
Add dtype and manipulation functions #1566
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
Conversation
View rendered docs @ https://intelpython.github.io/dpnp/pull/1566/index.html |
It seems we do not to skip the fallowing tests anymore. tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_0_{shapes=[(), ()]}::test_broadcast_arrays |
@npolina4 |
The below example works differently with numpy and description: a = numpy.ones((2, 3), dtype='i4')
b = a.astype('i4', copy=False)
b is a
# Out: True
a = dpnp.ones((2, 3), dtype='i4')
b = a.astype('i4', copy=False)
b is a
# Out: False |
Parameters | ||
---------- | ||
dtype : dtype | ||
Target data type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is about None
value? It would be good to state clearly, since dpctl and numpy supports that but might behave differently.
return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy) | ||
Parameters | ||
---------- | ||
dtype : dtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to describe x1
and casting
Otherwise, a copy is returned. | ||
Parameters | ||
---------- | ||
dtype : dtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to describe casting
Limitations | ||
----------- | ||
Parameter `subok` is supported with default value. | ||
Otherwise the function will be executed sequentially on CPU. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it would be better to get rid of the falling back on CPU and to raise an exception explicitly, like cupy does?
new_array = self.__new__(dpnp_array) | ||
new_array._array_obj = dpt.astype( | ||
self._array_obj, dtype, order=order, casting=casting, copy=copy | ||
return dpnp.astype( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to have main implementation here and then dpnp.astype
will be equal to
if dpnp.is_supported_array_type(x1):
return x1.astype(...)
else:
raise TypeError(...)
Also it will allow us to avoid invoking dpnp.get_usm_ndarray(...)
and dpnp_array._create_from_usm_ndarray(...)
.
@@ -150,30 +151,41 @@ def asnumpy(input, order="C"): | |||
|
|||
|
|||
def astype(x1, dtype, order="K", casting="unsafe", subok=True, copy=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither numpy or cupy has astype
method (they have it only in the context of ndarray), so I would propose to remove unsupported subok
parameter here.
------- | ||
out : dpnp.array | ||
If ``copy`` is False and no cast is required, then the array itself is returned. | ||
Otherwise, it returns a (possibly casted) copy of the array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds a bit unclear what "possibly casted" means. Could you please clarify that in the description or rephrase it.
In general, numpy and dpctl returns a view where possible.
@@ -597,32 +597,46 @@ def asnumpy(self): | |||
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. | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please check tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py::TestArrayCopyAndView
and unmute where possible?
Also it would be great refresh test_ndarray_copy_and_view.py
file.
RP will separate:
#1582 Leverage dpctl.tensor.iinfo() and dpctl.tensor.finfo() implementation.
#1583 Clean up old implementation of logic functions
#1585 Updated atleast_2d and atleast_3d functions
#1586 Implemented dpnp.tile function.
Add dtype and manipulation functions and tests.
Manipulation functions: dpnp.broadcast_arrays, dpnp.repeat, dpnp.vstack, dpnp.ravel
Data Type functions: dpnp.can_cast