|
50 | 50 |
|
51 | 51 | def _boolean_reduction(x, axis, keepdims, func): |
52 | 52 | if not isinstance(x, dpt.usm_ndarray): |
53 | | - raise TypeError(f"Expected dpctl.tensor.usm_ndarray, got {type(x)}") |
| 53 | + raise TypeError(f"Expected dpnp.tensor.usm_ndarray, got {type(x)}") |
54 | 54 |
|
55 | 55 | nd = x.ndim |
56 | 56 | if axis is None: |
@@ -118,59 +118,71 @@ def _boolean_reduction(x, axis, keepdims, func): |
118 | 118 |
|
119 | 119 | def all(x, /, *, axis=None, keepdims=False): |
120 | 120 | """ |
121 | | - all(x, axis=None, keepdims=False) |
122 | | -
|
123 | 121 | Tests whether all input array elements evaluate to True along a given axis. |
124 | 122 |
|
125 | | - Args: |
126 | | - x (usm_ndarray): Input array. |
127 | | - axis (Optional[Union[int, Tuple[int,...]]]): Axis (or axes) |
128 | | - along which to perform a logical AND reduction. |
129 | | - When `axis` is `None`, a logical AND reduction |
130 | | - is performed over all dimensions of `x`. |
131 | | - If `axis` is negative, the axis is counted from |
132 | | - the last dimension to the first. |
133 | | - Default: `None`. |
134 | | - keepdims (bool, optional): If `True`, the reduced axes are included |
135 | | - in the result as singleton dimensions, and the result is |
136 | | - broadcastable to the input array shape. |
137 | | - If `False`, the reduced axes are not included in the result. |
138 | | - Default: `False`. |
139 | | -
|
140 | | - Returns: |
141 | | - usm_ndarray: |
142 | | - An array with a data type of `bool` |
143 | | - containing the results of the logical AND reduction. |
| 123 | + Parameters |
| 124 | + ---------- |
| 125 | + x : usm_ndarray |
| 126 | + Input array. |
| 127 | + axis : {None, int, tuple of ints}, optional |
| 128 | + Axis (or axes) along which to perform a logical AND reduction. |
| 129 | + When `axis` is `None`, a logical AND reduction |
| 130 | + is performed over all dimensions of `x`. |
| 131 | + If `axis` is negative, the axis is counted from |
| 132 | + the last dimension to the first. |
| 133 | +
|
| 134 | + Default: ``None``. |
| 135 | + keepdims : bool, optional |
| 136 | + If `True`, the reduced axes are included in the result as |
| 137 | + singleton dimensions, and the result is broadcastable to the |
| 138 | + input array shape. |
| 139 | + If `False`, the reduced axes are not included in the result. |
| 140 | +
|
| 141 | + Default: ``False``. |
| 142 | +
|
| 143 | + Returns |
| 144 | + ------- |
| 145 | + out : usm_ndarray |
| 146 | + An array with a data type of `bool` |
| 147 | + containing the results of the logical AND reduction. |
| 148 | +
|
144 | 149 | """ |
| 150 | + |
145 | 151 | return _boolean_reduction(x, axis, keepdims, tri._all) |
146 | 152 |
|
147 | 153 |
|
148 | 154 | def any(x, /, *, axis=None, keepdims=False): |
149 | 155 | """ |
150 | | - any(x, axis=None, keepdims=False) |
151 | | -
|
152 | 156 | Tests whether any input array elements evaluate to True along a given axis. |
153 | 157 |
|
154 | | - Args: |
155 | | - x (usm_ndarray): Input array. |
156 | | - axis (Optional[Union[int, Tuple[int,...]]]): Axis (or axes) |
157 | | - along which to perform a logical OR reduction. |
158 | | - When `axis` is `None`, a logical OR reduction |
159 | | - is performed over all dimensions of `x`. |
160 | | - If `axis` is negative, the axis is counted from |
161 | | - the last dimension to the first. |
162 | | - Default: `None`. |
163 | | - keepdims (bool, optional): If `True`, the reduced axes are included |
164 | | - in the result as singleton dimensions, and the result is |
165 | | - broadcastable to the input array shape. |
166 | | - If `False`, the reduced axes are not included in the result. |
167 | | - Default: `False`. |
168 | | -
|
169 | | - Returns: |
170 | | - usm_ndarray: |
171 | | - An array with a data type of `bool` |
172 | | - containing the results of the logical OR reduction. |
| 158 | + Parameters |
| 159 | + ---------- |
| 160 | + x : usm_ndarray |
| 161 | + Input array. |
| 162 | + axis : {None, int, tuple of ints}, optional |
| 163 | + Axis (or axes) along which to perform a logical OR reduction. |
| 164 | + When `axis` is `None`, a logical OR reduction |
| 165 | + is performed over all dimensions of `x`. |
| 166 | + If `axis` is negative, the axis is counted from |
| 167 | + the last dimension to the first. |
| 168 | +
|
| 169 | + Default: ``None``. |
| 170 | + keepdims : bool, optional |
| 171 | + If `True`, the reduced axes are included in the result as |
| 172 | + singleton dimensions, and the result is broadcastable to the |
| 173 | + input array shape. |
| 174 | + If `False`, the reduced axes are not included in the result. |
| 175 | +
|
| 176 | + Default: ``False``. |
| 177 | +
|
| 178 | + Returns |
| 179 | + ------- |
| 180 | + out : usm_ndarray |
| 181 | + An array with a data type of `bool` |
| 182 | + containing the results of the logical OR reduction. |
| 183 | +
|
173 | 184 | """ |
| 185 | + |
174 | 186 | return _boolean_reduction(x, axis, keepdims, tri._any) |
175 | 187 |
|
176 | 188 |
|
@@ -432,43 +444,50 @@ def diff(x, /, *, axis=-1, n=1, prepend=None, append=None): |
432 | 444 | """ |
433 | 445 | Calculates the `n`-th discrete forward difference of `x` along `axis`. |
434 | 446 |
|
435 | | - Args: |
436 | | - x (usm_ndarray): |
437 | | - input array. |
438 | | - axis (int): |
439 | | - axis along which to compute the difference. A valid axis must be on |
440 | | - the interval `[-N, N)`, where `N` is the rank (number of |
441 | | - dimensions) of `x`. |
442 | | - Default: `-1` |
443 | | - n (int): |
444 | | - number of times to recursively compute the difference. |
445 | | - Default: `1`. |
446 | | - prepend (Union[usm_ndarray, bool, int, float, complex]): |
447 | | - value or values to prepend to the specified axis before taking the |
448 | | - difference. |
449 | | - Must have the same shape as `x` except along `axis`, which can have |
450 | | - any shape. |
451 | | - Default: `None`. |
452 | | - append (Union[usm_ndarray, bool, int, float, complex]): |
453 | | - value or values to append to the specified axis before taking the |
454 | | - difference. |
455 | | - Must have the same shape as `x` except along `axis`, which can have |
456 | | - any shape. |
457 | | - Default: `None`. |
458 | | -
|
459 | | - Returns: |
460 | | - usm_ndarray: |
461 | | - an array containing the `n`-th differences. The array will have the |
462 | | - same shape as `x`, except along `axis`, which will have shape: |
463 | | - ``prepend.shape[axis] + x.shape[axis] + append.shape[axis] - n`` |
464 | | -
|
465 | | - The data type of the returned array is determined by the Type |
466 | | - Promotion Rules. |
| 447 | + Parameters |
| 448 | + ---------- |
| 449 | + x : usm_ndarray |
| 450 | + Input array. |
| 451 | + axis : int, optional |
| 452 | + Axis along which to compute the difference. A valid axis must be on |
| 453 | + the interval `[-N, N)`, where `N` is the rank (number of |
| 454 | + dimensions) of `x`. |
| 455 | +
|
| 456 | + Default: ``-1``. |
| 457 | + n : int, optional |
| 458 | + Number of times to recursively compute the difference. |
| 459 | +
|
| 460 | + Default: ``1``. |
| 461 | + prepend : {None, usm_ndarray, bool, int, float, complex}, optional |
| 462 | + Value or values to prepend to the specified axis before taking the |
| 463 | + difference. |
| 464 | + Must have the same shape as `x` except along `axis`, which can have |
| 465 | + any shape. |
| 466 | +
|
| 467 | + Default: ``None``. |
| 468 | + append : {None, usm_ndarray, bool, int, float, complex}, optional |
| 469 | + Value or values to append to the specified axis before taking the |
| 470 | + difference. |
| 471 | + Must have the same shape as `x` except along `axis`, which can have |
| 472 | + any shape. |
| 473 | +
|
| 474 | + Default: ``None``. |
| 475 | +
|
| 476 | + Returns |
| 477 | + ------- |
| 478 | + out : usm_ndarray |
| 479 | + An array containing the `n`-th differences. The array will have the |
| 480 | + same shape as `x`, except along `axis`, which will have shape: |
| 481 | + ``prepend.shape[axis] + x.shape[axis] + append.shape[axis] - n`` |
| 482 | +
|
| 483 | + The data type of the returned array is determined by the Type |
| 484 | + Promotion Rules. |
| 485 | +
|
467 | 486 | """ |
468 | 487 |
|
469 | 488 | if not isinstance(x, dpt.usm_ndarray): |
470 | 489 | raise TypeError( |
471 | | - "Expecting dpctl.tensor.usm_ndarray type, " f"got {type(x)}" |
| 490 | + "Expecting dpnp.tensor.usm_ndarray type, " f"got {type(x)}" |
472 | 491 | ) |
473 | 492 | x_nd = x.ndim |
474 | 493 | axis = normalize_axis_index(operator.index(axis), x_nd) |
|
0 commit comments