Skip to content

Commit 4dc16b4

Browse files
authored
Leverage on out keyword in reduction and where functions of dpctl.tensor (#1808)
* Pass out keyword to dpctl in reduction functions * Pass out and order keywords to dpctl.tensor.where * Add wrapping methods to reduce code duplication * Update docstring comments * Resolve issue from spelling check * Separate wrapping function to reduction utils * Fix pre-commit issues * Fixed a typo * Applied review comments
1 parent 36ae1fe commit 4dc16b4

21 files changed

+854
-473
lines changed

.github/workflows/conda-package.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ env:
2727
test_logic.py
2828
test_manipulation.py
2929
test_mathematical.py
30+
test_nanfunctions.py
3031
test_product.py
3132
test_random_state.py
3233
test_sort.py
3334
test_special.py
3435
test_statistics.py
36+
test_sum.py
3537
test_sycl_queue.py
3638
test_umath.py
3739
test_usm_type.py

doc/known_words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Hadamard
2828
Hypergeometric
2929
iinfo
3030
Infs
31+
intp
3132
iterable
3233
Lomax
3334
Mersenne

dpnp/dpnp_algo/dpnp_arraycreation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class dpnp_nd_grid:
281281
282282
Parameters
283283
----------
284-
sparse : bool, optional
284+
sparse : {bool}, optional
285285
Whether the grid is sparse or not. Default is False.
286286
287287
"""

dpnp/dpnp_array.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ def argmax(self, axis=None, out=None, *, keepdims=False):
525525
Refer to :obj:`dpnp.argmax` for full documentation.
526526
527527
"""
528-
return dpnp.argmax(self, axis, out, keepdims=keepdims)
528+
529+
return dpnp.argmax(self, axis=axis, out=out, keepdims=keepdims)
529530

530531
def argmin(self, axis=None, out=None, *, keepdims=False):
531532
"""
@@ -534,7 +535,8 @@ def argmin(self, axis=None, out=None, *, keepdims=False):
534535
Refer to :obj:`dpnp.argmin` for full documentation.
535536
536537
"""
537-
return dpnp.argmin(self, axis, out, keepdims=keepdims)
538+
539+
return dpnp.argmin(self, axis=axis, out=out, keepdims=keepdims)
538540

539541
# 'argpartition',
540542

@@ -582,13 +584,15 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True):
582584
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
583585
Controls what kind of data casting may occur.
584586
Defaults to ``'unsafe'`` for backwards compatibility.
587+
585588
- 'no' means the data types should not be cast at all.
586589
- 'equiv' means only byte-order changes are allowed.
587590
- 'safe' means only casts which can preserve values are allowed.
588591
- 'same_kind' means only safe casts or casts within a kind, like
589592
float64 to float32, are allowed.
590593
- 'unsafe' means any data conversions may be done.
591-
copy : bool, optional
594+
595+
copy : {bool}, optional
592596
By default, ``astype`` always returns a newly allocated array. If
593597
this is set to ``False``, and the `dtype`, `order`, and `subok`
594598
requirements are satisfied, the input array is returned instead of
@@ -951,7 +955,14 @@ def max(
951955
952956
"""
953957

954-
return dpnp.max(self, axis, out, keepdims, initial, where)
958+
return dpnp.max(
959+
self,
960+
axis=axis,
961+
out=out,
962+
keepdims=keepdims,
963+
initial=initial,
964+
where=where,
965+
)
955966

956967
def mean(
957968
self, axis=None, dtype=None, out=None, keepdims=False, *, where=True
@@ -980,7 +991,14 @@ def min(
980991
981992
"""
982993

983-
return dpnp.min(self, axis, out, keepdims, initial, where)
994+
return dpnp.min(
995+
self,
996+
axis=axis,
997+
out=out,
998+
keepdims=keepdims,
999+
initial=initial,
1000+
where=where,
1001+
)
9841002

9851003
@property
9861004
def nbytes(self):
@@ -1054,7 +1072,15 @@ def prod(
10541072
10551073
"""
10561074

1057-
return dpnp.prod(self, axis, dtype, out, keepdims, initial, where)
1075+
return dpnp.prod(
1076+
self,
1077+
axis=axis,
1078+
dtype=dtype,
1079+
out=out,
1080+
keepdims=keepdims,
1081+
initial=initial,
1082+
where=where,
1083+
)
10581084

10591085
def put(self, indices, vals, /, *, axis=None, mode="wrap"):
10601086
"""
@@ -1295,13 +1321,11 @@ def strides(self):
12951321

12961322
def sum(
12971323
self,
1298-
/,
1299-
*,
13001324
axis=None,
13011325
dtype=None,
1302-
keepdims=False,
13031326
out=None,
1304-
initial=0,
1327+
keepdims=False,
1328+
initial=None,
13051329
where=True,
13061330
):
13071331
"""

dpnp/dpnp_iface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def astype(x1, dtype, order="K", casting="unsafe", copy=True):
209209
float64 to float32, are allowed.
210210
- 'unsafe' means any data conversions may be done.
211211
212-
copy : bool, optional
212+
copy : {bool}, optional
213213
By default, ``astype`` always returns a newly allocated array. If this
214214
is set to ``False``, and the `dtype`, `order`, and `subok` requirements
215215
are satisfied, the input array is returned instead of a copy.

dpnp/dpnp_iface_arraycreation.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def arange(
128128
step : {int, real}, optional
129129
Spacing between values. The default `step` size is 1. If `step`
130130
is specified as a position argument, `start` must also be given.
131-
dtype : dtype, optional
131+
dtype : {None, dtype}, optional
132132
The desired dtype for the array. If not given, a default dtype will be
133133
used that can represent the values (by considering Promotion Type Rule
134134
and device capabilities when necessary).
@@ -227,11 +227,11 @@ def array(
227227
Input data, in any form that can be converted to an array. This
228228
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
229229
tuples of lists, and ndarrays.
230-
dtype : dtype, optional
230+
dtype : {None, dtype}, optional
231231
The desired dtype for the array. If not given, a default dtype will be
232232
used that can represent the values (by considering Promotion Type Rule
233233
and device capabilities when necessary).
234-
copy : bool, optional
234+
copy : {bool}, optional
235235
If ``True`` (default), then the object is copied.
236236
order : {"C", "F", "A", "K"}, optional
237237
Memory layout of the newly output array. Default: "K".
@@ -353,7 +353,7 @@ def asanyarray(
353353
Input data, in any form that can be converted to an array. This
354354
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
355355
tuples of lists, and ndarrays.
356-
dtype : dtype, optional
356+
dtype : {None, dtype}, optional
357357
The desired dtype for the array. If not given, a default dtype will be
358358
used that can represent the values (by considering Promotion Type Rule
359359
and device capabilities when necessary).
@@ -449,7 +449,7 @@ def asarray(
449449
Input data, in any form that can be converted to an array. This
450450
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
451451
tuples of lists, and ndarrays.
452-
dtype : dtype, optional
452+
dtype : {None, dtype}, optional
453453
The desired dtype for the array. If not given, a default dtype will be
454454
used that can represent the values (by considering Promotion Type Rule
455455
and device capabilities when necessary).
@@ -540,7 +540,7 @@ def ascontiguousarray(
540540
Input data, in any form that can be converted to an array. This
541541
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
542542
tuples of lists, and ndarrays.
543-
dtype : dtype, optional
543+
dtype : {None, dtype}, optional
544544
The desired dtype for the array. If not given, a default dtype will be
545545
used that can represent the values (by considering Promotion Type Rule
546546
and device capabilities when necessary).
@@ -650,7 +650,7 @@ def asfortranarray(
650650
Input data, in any form that can be converted to an array. This
651651
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
652652
tuples of lists, and ndarrays.
653-
dtype : dtype, optional
653+
dtype : {None, dtype}, optional
654654
The desired dtype for the array. If not given, a default dtype will be
655655
used that can represent the values (by considering Promotion Type Rule
656656
and device capabilities when necessary).
@@ -1081,7 +1081,7 @@ def empty(
10811081
----------
10821082
shape : {int, sequence of ints}
10831083
Shape of the new array, e.g., (2, 3) or 2.
1084-
dtype : dtype, optional
1084+
dtype : {None, dtype}, optional
10851085
The desired dtype for the array, e.g., dpnp.int32.
10861086
Default is the default floating point data type for the device where
10871087
input array is allocated.
@@ -1179,7 +1179,7 @@ def empty_like(
11791179
a : {dpnp_array, usm_ndarray}
11801180
The shape and dtype of `a` define these same attributes
11811181
of the returned array.
1182-
dtype : dtype, optional
1182+
dtype : {None, dtype}, optional
11831183
The desired dtype for the array, e.g., dpnp.int32.
11841184
Default is the default floating point data type for the device where
11851185
input array is allocated.
@@ -1292,7 +1292,7 @@ def eye(
12921292
Index of the diagonal: 0 (the default) refers to the main diagonal,
12931293
a positive value refers to an upper diagonal, and a negative value to
12941294
a lower diagonal.
1295-
dtype : dtype, optional
1295+
dtype : {None, dtype}, optional
12961296
The desired dtype for the array, e.g., dpnp.int32.
12971297
Default is the default floating point data type for the device where
12981298
input array is allocated.
@@ -1902,7 +1902,7 @@ def full(
19021902
Fill value, in any form that can be converted to an array. This
19031903
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
19041904
tuples of lists, and ndarrays.
1905-
dtype : dtype, optional
1905+
dtype : {None, dtype}, optional
19061906
The desired dtype for the array, e.g., dpnp.int32.
19071907
Default is the default floating point data type for the device where
19081908
input array is allocated.
@@ -2003,7 +2003,7 @@ def full_like(
20032003
Fill value, in any form that can be converted to an array. This
20042004
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
20052005
tuples of lists, and ndarrays.
2006-
dtype : dtype, optional
2006+
dtype : {None, dtype}, optional
20072007
The desired dtype for the array, e.g., dpnp.int32.
20082008
Default is the default floating point data type for the device where
20092009
input array is allocated.
@@ -2121,7 +2121,7 @@ def geomspace(
21212121
all but the last (a sequence of length `num`) are returned.
21222122
num : int, optional
21232123
Number of samples to generate. Default is 50.
2124-
dtype : dtype, optional
2124+
dtype : {None, dtype}, optional
21252125
The desired dtype for the array. If not given, a default dtype will be
21262126
used that can represent the values (by considering Promotion Type Rule
21272127
and device capabilities when necessary).
@@ -2137,10 +2137,10 @@ def geomspace(
21372137
Default is ``None``.
21382138
sycl_queue : {None, SyclQueue}, optional
21392139
A SYCL queue to use for output array allocation and copying.
2140-
endpoint : bool, optional
2140+
endpoint : {bool}, optional
21412141
If ``True``, `stop` is the last sample. Otherwise, it is not included.
21422142
Default is ``True``.
2143-
axis : int, optional
2143+
axis : {int}, optional
21442144
The axis in the result to store the samples. Relevant only if start or
21452145
stop are array-like. By default (0), the samples will be along a new
21462146
axis inserted at the beginning. Use -1 to get an axis at the end.
@@ -2231,7 +2231,7 @@ def identity(
22312231
----------
22322232
n : int
22332233
Number of rows (and columns) in `n` x `n` output.
2234-
dtype : dtype, optional
2234+
dtype : {None, dtype}, optional
22352235
The desired dtype for the array, e.g., dpnp.int32.
22362236
Default is the default floating point data type for the device where
22372237
input array is allocated.
@@ -2342,7 +2342,7 @@ def linspace(
23422342
of tuples, tuples of lists, and ndarrays. If `endpoint` is set to
23432343
``False`` the sequence consists of all but the last of ``num + 1``
23442344
evenly spaced samples, so that `stop` is excluded.
2345-
dtype : dtype, optional
2345+
dtype : {None, dtype}, optional
23462346
The desired dtype for the array. If not given, a default dtype will be
23472347
used that can represent the values (by considering Promotion Type Rule
23482348
and device capabilities when necessary).
@@ -2358,13 +2358,13 @@ def linspace(
23582358
Default is ``None``.
23592359
sycl_queue : {None, SyclQueue}, optional
23602360
A SYCL queue to use for output array allocation and copying.
2361-
endpoint : bool, optional
2361+
endpoint : {bool}, optional
23622362
If ``True``, `stop` is the last sample. Otherwise, it is not included.
23632363
Default is ``True``.
2364-
retstep : bool, optional
2364+
retstep : {bool}, optional
23652365
If ``True``, return (samples, step), where step is the spacing between
23662366
samples.
2367-
axis : int, optional
2367+
axis : {int}, optional
23682368
The axis in the result to store the samples. Relevant only if start or
23692369
stop are array-like. By default (0), the samples will be along a new
23702370
axis inserted at the beginning. Use -1 to get an axis at the end.
@@ -2576,22 +2576,22 @@ def logspace(
25762576
Default is ``None``.
25772577
sycl_queue : {None, SyclQueue}, optional
25782578
A SYCL queue to use for output array allocation and copying.
2579-
endpoint : bool, optional
2579+
endpoint : {bool}, optional
25802580
If ``True``, stop is the last sample. Otherwise, it is not included.
25812581
Default is ``True``.
2582-
base : array_like, optional
2582+
base : {array_like}, optional
25832583
Input data, in any form that can be converted to an array. This
25842584
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
25852585
tuples of lists, and ndarrays. The base of the log space, in any form
25862586
that can be converted to an array.This includes scalars, lists, lists
25872587
of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.
25882588
The `step` size between the elements in ``ln(samples) / ln(base)``
25892589
(or log_base(samples)) is uniform. Default is 10.0.
2590-
dtype : dtype, optional
2590+
dtype : {None, dtype}, optional
25912591
The desired dtype for the array. If not given, a default dtype will be
25922592
used that can represent the values (by considering Promotion Type Rule
25932593
and device capabilities when necessary).
2594-
axis : int, optional
2594+
axis : {int}, optional
25952595
The axis in the result to store the samples. Relevant only if start,
25962596
stop, or base are array-like. By default (0), the samples will be along
25972597
a new axis inserted at the beginning. Use -1 to get an axis at the end.
@@ -2674,11 +2674,11 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"):
26742674
1-D arrays representing the coordinates of a grid.
26752675
indexing : {'xy', 'ij'}, optional
26762676
Cartesian (``'xy'``, default) or matrix (``'ij'``) indexing of output.
2677-
sparse : bool, optional
2677+
sparse : {bool}, optional
26782678
If True the shape of the returned coordinate array for dimension `i`
26792679
is reduced from ``(N1, ..., Ni, ... Nn)`` to
26802680
``(1, ..., 1, Ni, 1, ..., 1)``. Default is False.
2681-
copy : bool, optional
2681+
copy : {bool}, optional
26822682
If False, a view into the original arrays are returned in order to
26832683
conserve memory. Default is True.
26842684
@@ -2908,7 +2908,7 @@ def ones(
29082908
----------
29092909
shape : {int, sequence of ints}
29102910
Shape of the new array, e.g., (2, 3) or 2.
2911-
dtype : dtype, optional
2911+
dtype : {None, dtype}, optional
29122912
The desired dtype for the array, e.g., dpnp.int32.
29132913
Default is the default floating point data type for the device where
29142914
input array is allocated.
@@ -3012,7 +3012,7 @@ def ones_like(
30123012
a : {dpnp_array, usm_ndarray}
30133013
The shape and dtype of `a` define these same attributes
30143014
of the returned array.
3015-
dtype : dtype, optional
3015+
dtype : {None, dtype}, optional
30163016
The desired dtype for the array, e.g., dpnp.int32.
30173017
Default is the default floating point data type for the device where
30183018
input array is allocated.
@@ -3158,7 +3158,7 @@ def tri(
31583158
The sub-diagonal at and below which the array is filled. k = 0 is
31593159
the main diagonal, while k < 0 is below it, and k > 0 is above.
31603160
The default is 0.
3161-
dtype : dtype, optional
3161+
dtype : {None, dtype}, optional
31623162
The desired dtype for the array, e.g., dpnp.int32.
31633163
Default is the default floating point data type for the device where
31643164
input array is allocated.
@@ -3385,7 +3385,7 @@ def vander(
33853385
N : int, optional
33863386
Number of columns in the output. If `N` is not specified, a square
33873387
array is returned ``(N = len(x))``.
3388-
increasing : bool, optional
3388+
increasing : {bool}, optional
33893389
Order of the powers of the columns. If ``True,`` the powers increase
33903390
from left to right, if ``False`` (the default) they are reversed.
33913391
device : {None, string, SyclDevice, SyclQueue}, optional
@@ -3499,7 +3499,7 @@ def zeros(
34993499
----------
35003500
shape : {int, sequence of ints}
35013501
Shape of the new array, e.g., (2, 3) or 2.
3502-
dtype : dtype, optional
3502+
dtype : {None, dtype}, optional
35033503
The desired dtype for the array, e.g., dpnp.int32.
35043504
Default is the default floating point data type for the device where
35053505
input array is allocated.
@@ -3603,7 +3603,7 @@ def zeros_like(
36033603
a : {dpnp_array, usm_ndarray}
36043604
The shape and dtype of `a` define these same attributes
36053605
of the returned array.
3606-
dtype : dtype, optional
3606+
dtype : {None, dtype}, optional
36073607
The desired dtype for the array, e.g., dpnp.int32.
36083608
Default is the default floating point data type for the device where
36093609
input array is allocated.

0 commit comments

Comments
 (0)