Add implementation of dpnp.lib.stride_tricks.as_strided#2991
Add implementation of dpnp.lib.stride_tricks.as_strided#2991antonwolfy wants to merge 7 commits into
dpnp.lib.stride_tricks.as_strided#2991Conversation
3b47991 to
4b62bf8
Compare
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/2991/index.html |
|
Array API standard conformance tests for dpnp=0.21.0dev2=py313h509198e_19 ran successfully. |
| """ | ||
|
|
||
| dpnp.check_supported_arrays_type(x) | ||
| dpnp.check_limitations(subok=subok) |
There was a problem hiding this comment.
Would it be better to raise a warning or an error if the user passes a bool value to check_bounds parameter?
There was a problem hiding this comment.
We ignoring that keyword, why do we need to validate it?
| from ._version import get_versions | ||
| from . import exceptions as exceptions | ||
| from . import fft as fft | ||
| from . import lib as lib |
There was a problem hiding this comment.
do we need to add lib to submodules as is done for fft/ linalg on line 1060?
| a = generate_random_numpy_array((4,), dtype=dt) | ||
| ia = dpnp.array(a) | ||
|
|
||
| result = as_strided(ia, shape=(2,), strides=(2 * ia.itemsize,)) |
There was a problem hiding this comment.
If we pass strides that are not multiples of itemsize we willll get incorrect strides result
In [21]: a = dpnp.array([1, 2, 3, 4, 5], dtype="int32")
In [22]: a_np = dpnp.asnumpy(a)
In [23]: res = dpnp.lib.stride_tricks.as_strided(a, shape=(3,), strides=(6,))
In [24]: res_np = numpy.lib.stride_tricks.as_strided(a_np, shape=(3,), strides=(6,))
In [25]: res.strides
Out[25]: (4,)
In [26]: res_np.strides
Out[26]: (6,)
In [27]: res
Out[27]: array([1, 2, 3], dtype=int32)
In [28]: res_np
Out[28]: array([ 1, 196608, 4], dtype=int32)
Maybe it makes sense to add an error exception to ndarray stride logic?
This PR adds a new
dpnp.libnamespace and implementsdpnp.lib.stride_tricks.as_strided.The function creates a view into an array with a caller-specified shape and strides, sharing the base array's memory.
It closes #2969.