Skip to content

Commit 9d74e7e

Browse files
authored
Merge 1466bf6 into 808b976
2 parents 808b976 + 1466bf6 commit 9d74e7e

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

dpnp/dpnp_array.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,48 @@ def searchsorted(self, v, side="left", sorter=None):
12521252
@property
12531253
def shape(self):
12541254
"""
1255-
Lengths of axes. A tuple of numbers represents size of each dimension.
1255+
Tuple of array dimensions.
12561256
1257-
Setter of this property involves reshaping without copy. If the array
1258-
cannot be reshaped without copy, it raises an exception.
1257+
The shape property is usually used to get the current shape of an array,
1258+
but may also be used to reshape the array in-place by assigning a tuple
1259+
of array dimensions to it. Unlike :obj:`dpnp.reshape`, only non-negative
1260+
values are supported to be set as new shape. Reshaping an array in-place
1261+
will fail if a copy is required.
12591262
1260-
.. seealso: :attr:`numpy.ndarray.shape`
1263+
For full documentation refer to :obj:`numpy.ndarray.shape`.
1264+
1265+
Note
1266+
----
1267+
Using :obj:`dpnp.ndarray.reshape` or :obj:`dpnp.reshape is the
1268+
preferred approach to set new shape of an array.
1269+
1270+
See Also
1271+
--------
1272+
:obj:`dpnp.shape` : Equivalent getter function.
1273+
:obj:`dpnp.reshape` : Function similar to setting `shape`.
1274+
:obj:`dpnp.ndarray.reshape` : Method similar to setting `shape`.
1275+
1276+
Examples
1277+
--------
1278+
>>> import dpnp as np
1279+
>>> x = np.array([1, 2, 3, 4])
1280+
>>> x.shape
1281+
(4,)
1282+
>>> y = np.zeros((2, 3, 4))
1283+
>>> y.shape
1284+
(2, 3, 4)
1285+
1286+
>>> y.shape = (3, 8)
1287+
>>> y
1288+
array([[[0., 0., 0., 0.],
1289+
[0., 0., 0., 0.],
1290+
[0., 0., 0., 0.]],
1291+
[[0., 0., 0., 0.],
1292+
[0., 0., 0., 0.],
1293+
[0., 0., 0., 0.]]])
1294+
>>> y.shape = (3, 6)
1295+
...
1296+
TypeError: Can not reshape array of size 24 into (3, 6)
12611297
12621298
"""
12631299

@@ -1268,16 +1304,23 @@ def shape(self, newshape):
12681304
"""
12691305
Set new lengths of axes.
12701306
1271-
A tuple of numbers represents size of each dimension.
1272-
It involves reshaping without copy. If the array cannot be reshaped without copy,
1273-
it raises an exception.
1307+
Modifies array instamcee in-place by changing its metadata about the
1308+
shape and the strides of the array, or raises `AttributeError`
1309+
exception if in-place change is not possible.
12741310
1275-
.. seealso: :attr:`numpy.ndarray.shape`
1311+
Whether the array can be reshape in-place depends on its strides. Use
1312+
:obj:`dpnp.reshape` function which always succeeds to reshape the array
1313+
by performing a copy if necessary.
12761314
1277-
"""
1315+
For full documentation refer to :obj:`numpy.ndarray.shape`.
12781316
1279-
if not isinstance(newshape, (list, tuple)):
1280-
newshape = (newshape,)
1317+
Parameters
1318+
----------
1319+
newshape : {tuple, int}
1320+
New shape. Only non-negative values are supported. The new shape
1321+
may not lead to the change in the number of elements in the array.
1322+
1323+
"""
12811324

12821325
self._array_obj.shape = newshape
12831326

dpnp/dpnp_iface_logic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def array_equal(a1, a2, equal_nan=False):
459459
False, usm_type=usm_type_alloc, sycl_queue=sycl_queue_alloc
460460
)
461461
# Shapes of a1, a2 and masks are guaranteed to be consistent by this point
462+
# pylint:disable=invalid-unary-operand-type
462463
return (a1[~a1nan] == a2[~a1nan]).all()
463464

464465

0 commit comments

Comments
 (0)