Skip to content

Commit 4cc7e6f

Browse files
The reshape array method impl (#1014)
1 parent 02c6ba7 commit 4cc7e6f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

dpnp/dpnp_array.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,37 @@ def ndim(self):
514514
# 'ravel',
515515
# 'real',
516516
# 'repeat',
517-
# 'reshape',
517+
518+
def reshape(self, d0, *dn, order=b'C'):
519+
"""
520+
Returns an array containing the same data with a new shape.
521+
522+
Refer to `dpnp.reshape` for full documentation.
523+
524+
.. seealso::
525+
:meth:`numpy.ndarray.reshape`
526+
527+
Notes
528+
-----
529+
Unlike the free function `dpnp.reshape`, this method on `ndarray` allows
530+
the elements of the shape parameter to be passed in as separate arguments.
531+
For example, ``a.reshape(10, 11)`` is equivalent to
532+
``a.reshape((10, 11))``.
533+
534+
"""
535+
536+
if dn:
537+
if not isinstance(d0, int):
538+
msg_tmpl = "'{}' object cannot be interpreted as an integer"
539+
raise TypeError(msg_tmpl.format(type(d0).__name__))
540+
shape = [d0, *dn]
541+
else:
542+
shape = d0
543+
544+
shape_tup = dpnp.dpnp_utils._object_to_tuple(shape)
545+
546+
return dpnp.reshape(self, shape_tup)
547+
518548
# 'resize',
519549
# 'round',
520550
# 'searchsorted',

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_pa
132132
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto_where
133133
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto_where
134134
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto_where
135-
tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_invalid_order
136-
tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_with_changed_arraysize
137-
tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_with_multiple_unknown_dimensions
138135
tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize
139-
tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize_invalid
140136
tests/third_party/cupy/math_tests/test_sumprod.py::TestCumprod::test_cumprod_out_noncontiguous
141137
tests/third_party/cupy/math_tests/test_sumprod.py::TestCumsum_param_0_{axis=0}::test_cumsum_axis_out_noncontiguous
142138
tests/third_party/cupy/math_tests/test_sumprod.py::TestCumsum_param_0_{axis=0}::test_cumsum_out_noncontiguous

0 commit comments

Comments
 (0)