46
46
47
47
48
48
import dpctl .tensor as dpt
49
- import dpctl .tensor ._tensor_elementwise_impl as ti
49
+ import dpctl .tensor ._tensor_elementwise_impl as tei
50
50
import numpy
51
51
52
52
import dpnp
76
76
]
77
77
78
78
79
- def all (x , / , axis = None , out = None , keepdims = False , * , where = True ):
79
+ def all (a , / , axis = None , out = None , keepdims = False , * , where = True ):
80
80
"""
81
81
Test whether all array elements along a given axis evaluate to True.
82
82
83
83
For full documentation refer to :obj:`numpy.all`.
84
84
85
+ Parameters
86
+ ----------
87
+ a : {dpnp.ndarray, usm_ndarray}
88
+ Input array.
89
+ axis : {None, int, tuple of ints}, optional
90
+ Axis or axes along which a logical AND reduction is performed.
91
+ The default is to perform a logical AND over all the dimensions
92
+ of the input array.`axis` may be negative, in which case it counts
93
+ from the last to the first axis.
94
+ Default: ``None``.
95
+ out : {None, dpnp.ndarray, usm_ndarray}, optional
96
+ Alternative output array in which to place the result. It must have
97
+ the same shape as the expected output but the type (of the returned
98
+ values) will be cast if necessary.
99
+ Default: ``None``.
100
+ keepdims : bool, optional
101
+ If ``True``, the reduced axes (dimensions) are included in the result
102
+ as singleton dimensions, so that the returned array remains
103
+ compatible with the input array according to Array Broadcasting
104
+ rules. Otherwise, if ``False``, the reduced axes are not included in
105
+ the returned array.
106
+ Default: ``False``.
107
+
85
108
Returns
86
109
-------
87
110
out : dpnp.ndarray
88
111
An array with a data type of `bool`
89
- containing the results of the logical AND reduction.
112
+ containing the results of the logical AND reduction is returned
113
+ unless `out` is specified. Otherwise, a reference to `out` is returned.
114
+ The result has the same shape as `a` if `axis` is not ``None``
115
+ or `a` is a 0-d array.
90
116
91
117
Limitations
92
118
-----------
93
- Parameters `x` is supported either as :class:`dpnp.ndarray`
94
- or :class:`dpctl.tensor.usm_ndarray`.
95
- Parameters `out` and `where` are supported with default value.
96
- Input array data types are limited by supported DPNP :ref:`Data types`.
97
- Otherwise the function will be executed sequentially on CPU.
119
+ Parameters `where` is only supported with its default value.
120
+ Otherwise ``NotImplementedError`` exception will be raised.
98
121
99
122
See Also
100
123
--------
@@ -105,7 +128,7 @@ def all(x, /, axis=None, out=None, keepdims=False, *, where=True):
105
128
Notes
106
129
-----
107
130
Not a Number (NaN), positive infinity and negative infinity
108
- evaluate to `True` because these are not equal to zero.
131
+ evaluate to `` True` ` because these are not equal to zero.
109
132
110
133
Examples
111
134
--------
@@ -125,22 +148,27 @@ def all(x, /, axis=None, out=None, keepdims=False, *, where=True):
125
148
>>> np.all(x3)
126
149
array(True)
127
150
151
+ >>> o = np.array(False)
152
+ >>> z = np.all(x2, out=o)
153
+ >>> z, o
154
+ (array(True), array(True))
155
+ >>> # Check now that `z` is a reference to `o`
156
+ >>> z is o
157
+ True
158
+ >>> id(z), id(o) # identity of `z` and `o`
159
+ (139884456208480, 139884456208480) # may vary
160
+
128
161
"""
129
162
130
- if dpnp .is_supported_array_type (x ):
131
- if out is not None :
132
- pass
133
- elif where is not True :
134
- pass
135
- else :
136
- dpt_array = dpnp .get_usm_ndarray (x )
137
- return dpnp_array ._create_from_usm_ndarray (
138
- dpt .all (dpt_array , axis = axis , keepdims = keepdims )
139
- )
163
+ dpnp .check_limitations (where = where )
140
164
141
- return call_origin (
142
- numpy .all , x , axis = axis , out = out , keepdims = keepdims , where = where
165
+ dpt_array = dpnp .get_usm_ndarray (a )
166
+ result = dpnp_array ._create_from_usm_ndarray (
167
+ dpt .all (dpt_array , axis = axis , keepdims = keepdims )
143
168
)
169
+ # TODO: temporary solution until dpt.all supports out parameter
170
+ result = dpnp .get_result_array (result , out )
171
+ return result
144
172
145
173
146
174
def allclose (a , b , rtol = 1.0e-5 , atol = 1.0e-8 , ** kwargs ):
@@ -238,25 +266,48 @@ def allclose(a, b, rtol=1.0e-5, atol=1.0e-8, **kwargs):
238
266
return call_origin (numpy .allclose , a , b , rtol = rtol , atol = atol , ** kwargs )
239
267
240
268
241
- def any (x , / , axis = None , out = None , keepdims = False , * , where = True ):
269
+ def any (a , / , axis = None , out = None , keepdims = False , * , where = True ):
242
270
"""
243
271
Test whether any array element along a given axis evaluates to True.
244
272
245
273
For full documentation refer to :obj:`numpy.any`.
246
274
275
+ Parameters
276
+ ----------
277
+ a : {dpnp.ndarray, usm_ndarray}
278
+ Input array.
279
+ axis : {None, int, tuple of ints}, optional
280
+ Axis or axes along which a logical OR reduction is performed.
281
+ The default is to perform a logical OR over all the dimensions
282
+ of the input array.`axis` may be negative, in which case it counts
283
+ from the last to the first axis.
284
+ Default: ``None``.
285
+ out : {None, dpnp.ndarray, usm_ndarray}, optional
286
+ Alternative output array in which to place the result. It must have
287
+ the same shape as the expected output but the type (of the returned
288
+ values) will be cast if necessary.
289
+ Default: ``None``.
290
+ keepdims : bool, optional
291
+ If ``True``, the reduced axes (dimensions) are included in the result
292
+ as singleton dimensions, so that the returned array remains
293
+ compatible with the input array according to Array Broadcasting
294
+ rules. Otherwise, if ``False``, the reduced axes are not included in
295
+ the returned array.
296
+ Default: ``False``.
297
+
247
298
Returns
248
299
-------
249
300
out : dpnp.ndarray
250
301
An array with a data type of `bool`
251
- containing the results of the logical OR reduction.
302
+ containing the results of the logical OR reduction is returned
303
+ unless `out` is specified. Otherwise, a reference to `out` is returned.
304
+ The result has the same shape as `a` if `axis` is not ``None``
305
+ or `a` is a 0-d array.
252
306
253
307
Limitations
254
308
-----------
255
- Parameters `x` is supported either as :class:`dpnp.ndarray`
256
- or :class:`dpctl.tensor.usm_ndarray`.
257
- Parameters `out` and `where` are supported with default value.
258
- Input array data types are limited by supported DPNP :ref:`Data types`.
259
- Otherwise the function will be executed sequentially on CPU.
309
+ Parameters `where` is only supported with its default value.
310
+ Otherwise ``NotImplementedError`` exception will be raised.
260
311
261
312
See Also
262
313
--------
@@ -267,7 +318,7 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
267
318
Notes
268
319
-----
269
320
Not a Number (NaN), positive infinity and negative infinity evaluate
270
- to `True` because these are not equal to zero.
321
+ to `` True` ` because these are not equal to zero.
271
322
272
323
Examples
273
324
--------
@@ -279,30 +330,35 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
279
330
>>> np.any(x, axis=0)
280
331
array([ True, True])
281
332
282
- >>> x2 = np.array([0 , 0, 0 ])
333
+ >>> x2 = np.array([-1 , 0, 5 ])
283
334
>>> np.any(x2)
284
- array(False )
335
+ array(True )
285
336
286
337
>>> x3 = np.array([1.0, np.nan])
287
338
>>> np.any(x3)
288
339
array(True)
289
340
341
+ >>> o = np.array(False)
342
+ >>> z = np.any(x2, out=o)
343
+ >>> z, o
344
+ (array(True), array(True))
345
+ >>> # Check now that `z` is a reference to `o`
346
+ >>> z is o
347
+ True
348
+ >>> id(z), id(o) # identity of `z` and `o`
349
+ >>> (140053638309840, 140053638309840) # may vary
350
+
290
351
"""
291
352
292
- if dpnp .is_supported_array_type (x ):
293
- if out is not None :
294
- pass
295
- elif where is not True :
296
- pass
297
- else :
298
- dpt_array = dpnp .get_usm_ndarray (x )
299
- return dpnp_array ._create_from_usm_ndarray (
300
- dpt .any (dpt_array , axis = axis , keepdims = keepdims )
301
- )
353
+ dpnp .check_limitations (where = where )
302
354
303
- return call_origin (
304
- numpy .any , x , axis = axis , out = out , keepdims = keepdims , where = where
355
+ dpt_array = dpnp .get_usm_ndarray (a )
356
+ result = dpnp_array ._create_from_usm_ndarray (
357
+ dpt .any (dpt_array , axis = axis , keepdims = keepdims )
305
358
)
359
+ # TODO: temporary solution until dpt.any supports out parameter
360
+ result = dpnp .get_result_array (result , out )
361
+ return result
306
362
307
363
308
364
_EQUAL_DOCSTRING = """
@@ -368,8 +424,8 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
368
424
369
425
equal = DPNPBinaryFunc (
370
426
"equal" ,
371
- ti ._equal_result_type ,
372
- ti ._equal ,
427
+ tei ._equal_result_type ,
428
+ tei ._equal ,
373
429
_EQUAL_DOCSTRING ,
374
430
)
375
431
@@ -431,8 +487,8 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
431
487
432
488
greater = DPNPBinaryFunc (
433
489
"greater" ,
434
- ti ._greater_result_type ,
435
- ti ._greater ,
490
+ tei ._greater_result_type ,
491
+ tei ._greater ,
436
492
_GREATER_DOCSTRING ,
437
493
)
438
494
@@ -495,8 +551,8 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
495
551
496
552
greater_equal = DPNPBinaryFunc (
497
553
"greater" ,
498
- ti ._greater_equal_result_type ,
499
- ti ._greater_equal ,
554
+ tei ._greater_equal_result_type ,
555
+ tei ._greater_equal ,
500
556
_GREATER_EQUAL_DOCSTRING ,
501
557
)
502
558
@@ -597,8 +653,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
597
653
598
654
isfinite = DPNPUnaryFunc (
599
655
"isfinite" ,
600
- ti ._isfinite_result_type ,
601
- ti ._isfinite ,
656
+ tei ._isfinite_result_type ,
657
+ tei ._isfinite ,
602
658
_ISFINITE_DOCSTRING ,
603
659
)
604
660
@@ -650,8 +706,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
650
706
651
707
isinf = DPNPUnaryFunc (
652
708
"isinf" ,
653
- ti ._isinf_result_type ,
654
- ti ._isinf ,
709
+ tei ._isinf_result_type ,
710
+ tei ._isinf ,
655
711
_ISINF_DOCSTRING ,
656
712
)
657
713
@@ -704,8 +760,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
704
760
705
761
isnan = DPNPUnaryFunc (
706
762
"isnan" ,
707
- ti ._isnan_result_type ,
708
- ti ._isnan ,
763
+ tei ._isnan_result_type ,
764
+ tei ._isnan ,
709
765
_ISNAN_DOCSTRING ,
710
766
)
711
767
@@ -767,8 +823,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
767
823
768
824
less = DPNPBinaryFunc (
769
825
"less" ,
770
- ti ._less_result_type ,
771
- ti ._less ,
826
+ tei ._less_result_type ,
827
+ tei ._less ,
772
828
_LESS_DOCSTRING ,
773
829
)
774
830
@@ -830,8 +886,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
830
886
831
887
less_equal = DPNPBinaryFunc (
832
888
"less_equal" ,
833
- ti ._less_equal_result_type ,
834
- ti ._less_equal ,
889
+ tei ._less_equal_result_type ,
890
+ tei ._less_equal ,
835
891
_LESS_EQUAL_DOCSTRING ,
836
892
)
837
893
@@ -895,8 +951,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
895
951
896
952
logical_and = DPNPBinaryFunc (
897
953
"logical_and" ,
898
- ti ._logical_and_result_type ,
899
- ti ._logical_and ,
954
+ tei ._logical_and_result_type ,
955
+ tei ._logical_and ,
900
956
_LOGICAL_AND_DOCSTRING ,
901
957
)
902
958
@@ -947,8 +1003,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
947
1003
948
1004
logical_not = DPNPUnaryFunc (
949
1005
"logical_not" ,
950
- ti ._logical_not_result_type ,
951
- ti ._logical_not ,
1006
+ tei ._logical_not_result_type ,
1007
+ tei ._logical_not ,
952
1008
_LOGICAL_NOT_DOCSTRING ,
953
1009
)
954
1010
@@ -1012,8 +1068,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
1012
1068
1013
1069
logical_or = DPNPBinaryFunc (
1014
1070
"logical_or" ,
1015
- ti ._logical_or_result_type ,
1016
- ti ._logical_or ,
1071
+ tei ._logical_or_result_type ,
1072
+ tei ._logical_or ,
1017
1073
_LOGICAL_OR_DOCSTRING ,
1018
1074
)
1019
1075
@@ -1075,8 +1131,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
1075
1131
1076
1132
logical_xor = DPNPBinaryFunc (
1077
1133
"logical_xor" ,
1078
- ti ._logical_xor_result_type ,
1079
- ti ._logical_xor ,
1134
+ tei ._logical_xor_result_type ,
1135
+ tei ._logical_xor ,
1080
1136
_LOGICAL_XOR_DOCSTRING ,
1081
1137
)
1082
1138
@@ -1138,7 +1194,7 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
1138
1194
1139
1195
not_equal = DPNPBinaryFunc (
1140
1196
"not_equal" ,
1141
- ti ._not_equal_result_type ,
1142
- ti ._not_equal ,
1197
+ tei ._not_equal_result_type ,
1198
+ tei ._not_equal ,
1143
1199
_NOT_EQUAL_DOCSTRING ,
1144
1200
)
0 commit comments