15
15
from ._flags import requires_api_version
16
16
from ._creation_functions import asarray
17
17
from ._data_type_functions import broadcast_to , iinfo
18
+ from ._helpers import _maybe_normalize_py_scalars
18
19
19
20
from typing import Optional , Union
20
21
@@ -62,6 +63,8 @@ def add(x1: Array, x2: Array, /) -> Array:
62
63
63
64
See its docstring for more information.
64
65
"""
66
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
67
+
65
68
if x1 .device != x2 .device :
66
69
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
67
70
@@ -116,6 +119,8 @@ def atan2(x1: Array, x2: Array, /) -> Array:
116
119
117
120
See its docstring for more information.
118
121
"""
122
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
123
+
119
124
if x1 .device != x2 .device :
120
125
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
121
126
if x1 .dtype not in _real_floating_dtypes or x2 .dtype not in _real_floating_dtypes :
@@ -144,6 +149,8 @@ def bitwise_and(x1: Array, x2: Array, /) -> Array:
144
149
145
150
See its docstring for more information.
146
151
"""
152
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
153
+
147
154
if x1 .device != x2 .device :
148
155
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
149
156
@@ -165,6 +172,8 @@ def bitwise_left_shift(x1: Array, x2: Array, /) -> Array:
165
172
166
173
See its docstring for more information.
167
174
"""
175
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
176
+
168
177
if x1 .device != x2 .device :
169
178
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
170
179
@@ -197,6 +206,8 @@ def bitwise_or(x1: Array, x2: Array, /) -> Array:
197
206
198
207
See its docstring for more information.
199
208
"""
209
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
210
+
200
211
if x1 .device != x2 .device :
201
212
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
202
213
@@ -218,6 +229,8 @@ def bitwise_right_shift(x1: Array, x2: Array, /) -> Array:
218
229
219
230
See its docstring for more information.
220
231
"""
232
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
233
+
221
234
if x1 .device != x2 .device :
222
235
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
223
236
@@ -238,6 +251,8 @@ def bitwise_xor(x1: Array, x2: Array, /) -> Array:
238
251
239
252
See its docstring for more information.
240
253
"""
254
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
255
+
241
256
if x1 .device != x2 .device :
242
257
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
243
258
@@ -389,6 +404,8 @@ def copysign(x1: Array, x2: Array, /) -> Array:
389
404
390
405
See its docstring for more information.
391
406
"""
407
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
408
+
392
409
if x1 .device != x2 .device :
393
410
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
394
411
@@ -427,6 +444,8 @@ def divide(x1: Array, x2: Array, /) -> Array:
427
444
428
445
See its docstring for more information.
429
446
"""
447
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
448
+
430
449
if x1 .device != x2 .device :
431
450
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
432
451
if x1 .dtype not in _floating_dtypes or x2 .dtype not in _floating_dtypes :
@@ -443,6 +462,8 @@ def equal(x1: Array, x2: Array, /) -> Array:
443
462
444
463
See its docstring for more information.
445
464
"""
465
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
466
+
446
467
if x1 .device != x2 .device :
447
468
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
448
469
# Call result type here just to raise on disallowed type combinations
@@ -493,6 +514,8 @@ def floor_divide(x1: Array, x2: Array, /) -> Array:
493
514
494
515
See its docstring for more information.
495
516
"""
517
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
518
+
496
519
if x1 .device != x2 .device :
497
520
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
498
521
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -509,6 +532,8 @@ def greater(x1: Array, x2: Array, /) -> Array:
509
532
510
533
See its docstring for more information.
511
534
"""
535
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
536
+
512
537
if x1 .device != x2 .device :
513
538
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
514
539
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -525,6 +550,8 @@ def greater_equal(x1: Array, x2: Array, /) -> Array:
525
550
526
551
See its docstring for more information.
527
552
"""
553
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
554
+
528
555
if x1 .device != x2 .device :
529
556
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
530
557
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -541,6 +568,8 @@ def hypot(x1: Array, x2: Array, /) -> Array:
541
568
542
569
See its docstring for more information.
543
570
"""
571
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
572
+
544
573
if x1 .device != x2 .device :
545
574
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
546
575
if x1 .dtype not in _real_floating_dtypes or x2 .dtype not in _real_floating_dtypes :
@@ -600,6 +629,8 @@ def less(x1: Array, x2: Array, /) -> Array:
600
629
601
630
See its docstring for more information.
602
631
"""
632
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
633
+
603
634
if x1 .device != x2 .device :
604
635
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
605
636
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -616,6 +647,8 @@ def less_equal(x1: Array, x2: Array, /) -> Array:
616
647
617
648
See its docstring for more information.
618
649
"""
650
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
651
+
619
652
if x1 .device != x2 .device :
620
653
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
621
654
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -676,6 +709,8 @@ def logaddexp(x1: Array, x2: Array, /) -> Array:
676
709
677
710
See its docstring for more information.
678
711
"""
712
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
713
+
679
714
if x1 .device != x2 .device :
680
715
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
681
716
if x1 .dtype not in _real_floating_dtypes or x2 .dtype not in _real_floating_dtypes :
@@ -692,6 +727,8 @@ def logical_and(x1: Array, x2: Array, /) -> Array:
692
727
693
728
See its docstring for more information.
694
729
"""
730
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
731
+
695
732
if x1 .device != x2 .device :
696
733
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
697
734
if x1 .dtype not in _boolean_dtypes or x2 .dtype not in _boolean_dtypes :
@@ -719,6 +756,8 @@ def logical_or(x1: Array, x2: Array, /) -> Array:
719
756
720
757
See its docstring for more information.
721
758
"""
759
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
760
+
722
761
if x1 .device != x2 .device :
723
762
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
724
763
if x1 .dtype not in _boolean_dtypes or x2 .dtype not in _boolean_dtypes :
@@ -735,6 +774,8 @@ def logical_xor(x1: Array, x2: Array, /) -> Array:
735
774
736
775
See its docstring for more information.
737
776
"""
777
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
778
+
738
779
if x1 .device != x2 .device :
739
780
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
740
781
if x1 .dtype not in _boolean_dtypes or x2 .dtype not in _boolean_dtypes :
@@ -751,6 +792,8 @@ def maximum(x1: Array, x2: Array, /) -> Array:
751
792
752
793
See its docstring for more information.
753
794
"""
795
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
796
+
754
797
if x1 .device != x2 .device :
755
798
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
756
799
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -769,6 +812,8 @@ def minimum(x1: Array, x2: Array, /) -> Array:
769
812
770
813
See its docstring for more information.
771
814
"""
815
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
816
+
772
817
if x1 .device != x2 .device :
773
818
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
774
819
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -784,6 +829,8 @@ def multiply(x1: Array, x2: Array, /) -> Array:
784
829
785
830
See its docstring for more information.
786
831
"""
832
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
833
+
787
834
if x1 .device != x2 .device :
788
835
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
789
836
if x1 .dtype not in _numeric_dtypes or x2 .dtype not in _numeric_dtypes :
@@ -812,6 +859,8 @@ def nextafter(x1: Array, x2: Array, /) -> Array:
812
859
813
860
See its docstring for more information.
814
861
"""
862
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
863
+
815
864
if x1 .device != x2 .device :
816
865
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
817
866
if x1 .dtype not in _real_floating_dtypes or x2 .dtype not in _real_floating_dtypes :
@@ -825,6 +874,8 @@ def not_equal(x1: Array, x2: Array, /) -> Array:
825
874
826
875
See its docstring for more information.
827
876
"""
877
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
878
+
828
879
if x1 .device != x2 .device :
829
880
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
830
881
# Call result type here just to raise on disallowed type combinations
@@ -851,6 +902,8 @@ def pow(x1: Array, x2: Array, /) -> Array:
851
902
852
903
See its docstring for more information.
853
904
"""
905
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
906
+
854
907
if x1 .device != x2 .device :
855
908
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
856
909
if x1 .dtype not in _numeric_dtypes or x2 .dtype not in _numeric_dtypes :
@@ -889,6 +942,8 @@ def remainder(x1: Array, x2: Array, /) -> Array:
889
942
890
943
See its docstring for more information.
891
944
"""
945
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
946
+
892
947
if x1 .device != x2 .device :
893
948
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
894
949
if x1 .dtype not in _real_numeric_dtypes or x2 .dtype not in _real_numeric_dtypes :
@@ -985,6 +1040,8 @@ def subtract(x1: Array, x2: Array, /) -> Array:
985
1040
986
1041
See its docstring for more information.
987
1042
"""
1043
+ x1 , x2 = _maybe_normalize_py_scalars (x1 , x2 )
1044
+
988
1045
if x1 .device != x2 .device :
989
1046
raise ValueError (f"Arrays from two different devices ({ x1 .device } and { x2 .device } ) can not be combined." )
990
1047
if x1 .dtype not in _numeric_dtypes or x2 .dtype not in _numeric_dtypes :
0 commit comments