diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 6af473fc5ed..e372fc3dffe 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -870,14 +870,21 @@ def prod(self, axis=None, dtype=None, out=None, keepdims=False, initial=None, wh # 'real', # 'repeat', - def reshape(self, d0, *dn, order=b'C'): + def reshape(self, *sh, **kwargs): """ Returns an array containing the same data with a new shape. - Refer to `dpnp.reshape` for full documentation. + For full documentation refer to :obj:`numpy.ndarray.reshape`. - .. seealso:: - :meth:`numpy.ndarray.reshape` + Returns + ------- + y : dpnp.ndarray + This will be a new view object if possible; + otherwise, it will be a copy. + + See Also + -------- + :obj:`dpnp.reshape` : Equivalent function. Notes ----- @@ -888,17 +895,9 @@ def reshape(self, d0, *dn, order=b'C'): """ - if dn: - if not isinstance(d0, int): - msg_tmpl = "'{}' object cannot be interpreted as an integer" - raise TypeError(msg_tmpl.format(type(d0).__name__)) - shape = [d0, *dn] - else: - shape = d0 - - shape_tup = dpnp.dpnp_utils._object_to_tuple(shape) - - return dpnp.reshape(self, shape_tup) + if len(sh) == 1: + sh = sh[0] + return dpnp.reshape(self, sh, **kwargs) # 'resize', @@ -940,14 +939,7 @@ def shape(self, newshape): """ - dpnp.reshape(self, newshape) - - @property - def shape(self): - """ - """ - - return self._array_obj.shape + dpnp.reshape(self, newshape=newshape) @property def size(self): diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 5c879ac4cb4..cadf63af236 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -68,6 +68,7 @@ "repeat", "reshape", "rollaxis", + "shape", "squeeze", "stack", "swapaxes", @@ -501,26 +502,81 @@ def repeat(x1, repeats, axis=None): return call_origin(numpy.repeat, x1, repeats, axis) -def reshape(x1, newshape, order='C'): +def reshape(x, /, newshape, order='C', copy=None): """ Gives a new shape to an array without changing its data. For full documentation refer to :obj:`numpy.reshape`. + Parameters + ---------- + x : {dpnp_array, usm_ndarray} + Array to be reshaped. + newshape : int or tuple of ints + The new shape should be compatible with the original shape. If + an integer, then the result will be a 1-D array of that length. + One shape dimension can be -1. In this case, the value is + inferred from the length of the array and remaining dimensions. + order : {'C', 'F'}, optional + Read the elements of `x` using this index order, and place the + elements into the reshaped array using this index order. 'C' + means to read / write the elements using C-like index order, + with the last axis index changing fastest, back to the first + axis index changing slowest. 'F' means to read / write the + elements using Fortran-like index order, with the first index + changing fastest, and the last index changing slowest. Note that + the 'C' and 'F' options take no account of the memory layout of + the underlying array, and only refer to the order of indexing. + copy : bool, optional + Boolean indicating whether or not to copy the input array. + If ``True``, the result array will always be a copy of input `x`. + If ``False``, the result array can never be a copy + and a ValueError exception will be raised in case the copy is necessary. + If ``None``, the result array will reuse existing memory buffer of `x` + if possible and copy otherwise. Default: None. + + Returns + ------- + y : dpnp.ndarray + This will be a new view object if possible; otherwise, it will + be a copy. Note there is no guarantee of the *memory layout* (C- or + Fortran- contiguous) of the returned array. + Limitations ----------- - Only 'C' order is supported. + Parameter `order` is supported only with values ``"C"`` and ``"F"``. + + See Also + -------- + :obj:`dpnp.ndarray.reshape` : Equivalent method. + + Examples + -------- + >>> import dpnp as dp + >>> a = dp.array([[1, 2, 3], [4, 5, 6]]) + >>> dp.reshape(a, 6) + array([1, 2, 3, 4, 5, 6]) + >>> dp.reshape(a, 6, order='F') + array([1, 4, 2, 5, 3, 6]) + + >>> dp.reshape(a, (3, -1)) # the unspecified value is inferred to be 2 + array([[1, 2], + [3, 4], + [5, 6]]) """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: - if order != 'C': - pass - else: - return dpnp_reshape(x1_desc, newshape, order).get_pyobj() + if newshape is None: + newshape = x.shape - return call_origin(numpy.reshape, x1, newshape, order) + if order is None: + order = 'C' + elif not order in "cfCF": + raise ValueError(f"order must be one of 'C' or 'F' (got {order})") + + usm_arr = dpnp.get_usm_ndarray(x) + usm_arr = dpt.reshape(usm_arr, shape=newshape, order=order, copy=copy) + return dpnp_array._create_from_usm_ndarray(usm_arr) def rollaxis(x1, axis, start=0): @@ -571,6 +627,49 @@ def rollaxis(x1, axis, start=0): return call_origin(numpy.rollaxis, x1, axis, start) +def shape(a): + """ + Return the shape of an array. + + For full documentation refer to :obj:`numpy.shape`. + + Parameters + ---------- + a : array_like + Input array. + + Returns + ------- + shape : tuple of ints + The elements of the shape tuple give the lengths of the + corresponding array dimensions. + + See Also + -------- + len : ``len(a)`` is equivalent to ``np.shape(a)[0]`` for N-D arrays with + ``N>=1``. + :obj:`dpnp.ndarray.shape` : Equivalent array method. + + Examples + -------- + >>> import dpnp as dp + >>> dp.shape(dp.eye(3)) + (3, 3) + >>> dp.shape([[1, 3]]) + (1, 2) + >>> dp.shape([0]) + (1,) + >>> dp.shape(0) + () + + """ + + if dpnp.is_supported_array_type(a): + return a.shape + else: + return numpy.shape(a) + + def squeeze(x, /, axis=None): """ Removes singleton dimensions (axes) from array `x`. diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index de030b5e415..53d652c86e8 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -680,55 +680,9 @@ tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel2 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel3 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_external_ravel tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_0_{order_init='C', order_reshape='C', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_10_{order_init='C', order_reshape='c', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_11_{order_init='C', order_reshape='c', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_12_{order_init='C', order_reshape='f', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_13_{order_init='C', order_reshape='f', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_14_{order_init='C', order_reshape='f', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_15_{order_init='C', order_reshape='a', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_16_{order_init='C', order_reshape='a', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_17_{order_init='C', order_reshape='a', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_18_{order_init='F', order_reshape='C', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_19_{order_init='F', order_reshape='C', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_1_{order_init='C', order_reshape='C', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_20_{order_init='F', order_reshape='C', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_21_{order_init='F', order_reshape='F', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_22_{order_init='F', order_reshape='F', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_23_{order_init='F', order_reshape='F', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_24_{order_init='F', order_reshape='A', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_25_{order_init='F', order_reshape='A', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_26_{order_init='F', order_reshape='A', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_27_{order_init='F', order_reshape='c', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_28_{order_init='F', order_reshape='c', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_29_{order_init='F', order_reshape='c', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_2_{order_init='C', order_reshape='C', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_30_{order_init='F', order_reshape='f', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_31_{order_init='F', order_reshape='f', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_32_{order_init='F', order_reshape='f', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_33_{order_init='F', order_reshape='a', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_34_{order_init='F', order_reshape='a', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_35_{order_init='F', order_reshape='a', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_3_{order_init='C', order_reshape='F', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_4_{order_init='C', order_reshape='F', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_5_{order_init='C', order_reshape='F', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_6_{order_init='C', order_reshape='A', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_7_{order_init='C', order_reshape='A', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_8_{order_init='C', order_reshape='A', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_9_{order_init='C', order_reshape='c', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_external_reshape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_nocopy_reshape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_nocopy_reshape_with_order -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape2 -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_strides -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_with_unknown_dimension -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_transposed_reshape2 -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_0_{shape=(2, 3)}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_0_{shape=(2, 3)}::test_shape_list -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_1_{shape=()}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_1_{shape=()}::test_shape_list -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_2_{shape=(4,)}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_2_{shape=(4,)}::test_shape_list +tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize +tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize2 + tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_func tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_method tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_0_{reps=-1}::test_tile_failure diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index eee15ebc487..7968475996d 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -243,7 +243,7 @@ tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_pa tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto_where tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto_where tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto_where -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize + tests/third_party/cupy/math_tests/test_sumprod.py::TestCumprod::test_cumprod_out_noncontiguous tests/third_party/cupy/math_tests/test_sumprod.py::TestCumsum_param_0_{axis=0}::test_cumsum_axis_out_noncontiguous tests/third_party/cupy/math_tests/test_sumprod.py::TestCumsum_param_0_{axis=0}::test_cumsum_out_noncontiguous @@ -818,55 +818,9 @@ tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel2 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel3 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_external_ravel tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_0_{order_init='C', order_reshape='C', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_10_{order_init='C', order_reshape='c', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_11_{order_init='C', order_reshape='c', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_12_{order_init='C', order_reshape='f', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_13_{order_init='C', order_reshape='f', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_14_{order_init='C', order_reshape='f', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_15_{order_init='C', order_reshape='a', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_16_{order_init='C', order_reshape='a', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_17_{order_init='C', order_reshape='a', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_18_{order_init='F', order_reshape='C', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_19_{order_init='F', order_reshape='C', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_1_{order_init='C', order_reshape='C', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_20_{order_init='F', order_reshape='C', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_21_{order_init='F', order_reshape='F', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_22_{order_init='F', order_reshape='F', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_23_{order_init='F', order_reshape='F', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_24_{order_init='F', order_reshape='A', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_25_{order_init='F', order_reshape='A', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_26_{order_init='F', order_reshape='A', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_27_{order_init='F', order_reshape='c', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_28_{order_init='F', order_reshape='c', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_29_{order_init='F', order_reshape='c', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_2_{order_init='C', order_reshape='C', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_30_{order_init='F', order_reshape='f', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_31_{order_init='F', order_reshape='f', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_32_{order_init='F', order_reshape='f', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_33_{order_init='F', order_reshape='a', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_34_{order_init='F', order_reshape='a', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_35_{order_init='F', order_reshape='a', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_3_{order_init='C', order_reshape='F', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_4_{order_init='C', order_reshape='F', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_5_{order_init='C', order_reshape='F', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_6_{order_init='C', order_reshape='A', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_7_{order_init='C', order_reshape='A', shape_in_out=((6,), (2, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_8_{order_init='C', order_reshape='A', shape_in_out=((3, 3, 3), (9, 3))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshapeOrder_param_9_{order_init='C', order_reshape='c', shape_in_out=((2, 3), (1, 6, 1))}::test_reshape_contiguity -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_external_reshape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_nocopy_reshape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_nocopy_reshape_with_order -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape2 -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_strides -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_with_unknown_dimension -tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_transposed_reshape2 -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_0_{shape=(2, 3)}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_0_{shape=(2, 3)}::test_shape_list -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_1_{shape=()}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_1_{shape=()}::test_shape_list -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_2_{shape=(4,)}::test_shape -tests/third_party/cupy/manipulation_tests/test_shape.py::TestShape_param_2_{shape=(4,)}::test_shape_list +tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize +tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize2 + tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_func tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_method tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_0_{reps=-1}::test_tile_failure diff --git a/tests/third_party/cupy/manipulation_tests/test_shape.py b/tests/third_party/cupy/manipulation_tests/test_shape.py index b80437dba89..826c0e49011 100644 --- a/tests/third_party/cupy/manipulation_tests/test_shape.py +++ b/tests/third_party/cupy/manipulation_tests/test_shape.py @@ -28,20 +28,22 @@ def test_shape_list(self): @testing.gpu class TestReshape(unittest.TestCase): + # order = 'A' is out of support currently + _supported_orders = 'CF' - def test_reshape_strides(self): + def test_reshape_shapes(self): def func(xp): a = testing.shaped_arange((1, 1, 1, 2, 2), xp) - return a.strides - self.assertEqual(func(numpy), func(cupy)) + return a.shape + assert func(numpy) == func(cupy) def test_reshape2(self): def func(xp): a = xp.zeros((8,), dtype=xp.float32) - return a.reshape((1, 1, 1, 4, 1, 2)).strides - self.assertEqual(func(numpy), func(cupy)) + return a.reshape((1, 1, 1, 4, 1, 2)).shape + assert func(numpy) == func(cupy) - @testing.for_orders('CFA') + @testing.for_orders(_supported_orders) @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_nocopy_reshape(self, xp, dtype, order): @@ -50,7 +52,7 @@ def test_nocopy_reshape(self, xp, dtype, order): b[1] = 1 return a - @testing.for_orders('CFA') + @testing.for_orders(_supported_orders) @testing.for_all_dtypes() @testing.numpy_cupy_array_equal() def test_nocopy_reshape_with_order(self, xp, dtype, order): @@ -59,13 +61,13 @@ def test_nocopy_reshape_with_order(self, xp, dtype, order): b[1] = 1 return a - @testing.for_orders('CFA') + @testing.for_orders(_supported_orders) @testing.numpy_cupy_array_equal() def test_transposed_reshape2(self, xp, order): a = testing.shaped_arange((2, 3, 4), xp).transpose(2, 0, 1) return a.reshape(2, 3, 4, order=order) - @testing.for_orders('CFA') + @testing.for_orders(_supported_orders) @testing.numpy_cupy_array_equal() def test_reshape_with_unknown_dimension(self, xp, order): a = testing.shaped_arange((2, 3, 4), xp) @@ -95,17 +97,58 @@ def test_reshape_zerosize_invalid(self): with pytest.raises(ValueError): a.reshape(()) + def test_reshape_zerosize_invalid_unknown(self): + for xp in (numpy, cupy): + a = xp.zeros((0,)) + with pytest.raises(ValueError): + a.reshape((-1, 0)) + @testing.numpy_cupy_array_equal() def test_reshape_zerosize(self, xp): a = xp.zeros((0,)) - return a.reshape((0,)) - - @testing.for_orders('CFA') + b = a.reshape((0,)) + assert b.base is a + return b + + @testing.for_orders(_supported_orders) + @testing.numpy_cupy_array_equal(strides_check=True) + def test_reshape_zerosize2(self, xp, order): + a = xp.zeros((2, 0, 3)) + b = a.reshape((5, 0, 4), order=order) + assert b.base is a + return b + + @testing.for_orders(_supported_orders) @testing.numpy_cupy_array_equal() def test_external_reshape(self, xp, order): a = xp.zeros((8,), dtype=xp.float32) return xp.reshape(a, (1, 1, 1, 4, 1, 2), order=order) + def _test_ndim_limit(self, xp, ndim, dtype, order): + idx = [1]*ndim + idx[-1] = ndim + a = xp.ones(ndim, dtype=dtype) + a = a.reshape(idx, order=order) + assert a.ndim == ndim + return a + + @testing.for_orders(_supported_orders) + @testing.for_all_dtypes() + @testing.numpy_cupy_array_equal() + def test_ndim_limit1(self, xp, dtype, order): + # from cupy/cupy#4193 + a = self._test_ndim_limit(xp, 32, dtype, order) + return a + + @pytest.mark.skip("no max ndim limit for reshape in dpctl") + @testing.for_orders(_supported_orders) + @testing.for_all_dtypes() + def test_ndim_limit2(self, dtype, order): + # from cupy/cupy#4193 + for xp in (numpy, cupy): + with pytest.raises(ValueError): + self._test_ndim_limit(xp, 33, dtype, order) + @testing.gpu class TestRavel(unittest.TestCase): @@ -139,7 +182,9 @@ def test_external_ravel(self, xp): @testing.parameterize(*testing.product({ 'order_init': ['C', 'F'], - 'order_reshape': ['C', 'F', 'A', 'c', 'f', 'a'], + # order = 'A' is out of support currently + # 'order_reshape': ['C', 'F', 'A', 'c', 'f', 'a'], + 'order_reshape': ['C', 'F', 'c', 'f'], 'shape_in_out': [((2, 3), (1, 6, 1)), # (shape_init, shape_final) ((6,), (2, 3)), ((3, 3, 3), (9, 3))], @@ -161,5 +206,4 @@ def test_reshape_contiguity(self): assert b_cupy.flags.f_contiguous == b_numpy.flags.f_contiguous assert b_cupy.flags.c_contiguous == b_numpy.flags.c_contiguous - testing.assert_array_equal(b_cupy.strides, b_numpy.strides) testing.assert_array_equal(b_cupy, b_numpy) diff --git a/tests/third_party/cupy/math_tests/test_sumprod.py b/tests/third_party/cupy/math_tests/test_sumprod.py index d9fe3b22b26..17250257fe8 100644 --- a/tests/third_party/cupy/math_tests/test_sumprod.py +++ b/tests/third_party/cupy/math_tests/test_sumprod.py @@ -41,7 +41,7 @@ def test_sum_all2(self, xp, dtype): return a.sum() @testing.for_all_dtypes() - @testing.numpy_cupy_allclose() + @testing.numpy_cupy_allclose(type_check=False) def test_sum_all_transposed(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(2, 0, 1) return a.sum() diff --git a/tests/third_party/cupy/testing/__init__.py b/tests/third_party/cupy/testing/__init__.py index 09f30ade6d9..56b5d052958 100644 --- a/tests/third_party/cupy/testing/__init__.py +++ b/tests/third_party/cupy/testing/__init__.py @@ -7,7 +7,7 @@ from tests.third_party.cupy.testing.array import assert_allclose from tests.third_party.cupy.testing.array import assert_array_almost_equal # from tests.third_party.cupy.testing.array import assert_array_almost_equal_nulp -# from tests.third_party.cupy.testing.array import assert_array_equal +from tests.third_party.cupy.testing.array import assert_array_equal # from tests.third_party.cupy.testing.array import assert_array_less # from tests.third_party.cupy.testing.array import assert_array_list_equal # from tests.third_party.cupy.testing.array import assert_array_max_ulp