Skip to content

Commit 96f40fe

Browse files
committed
Ignore warnings in array API functions that can raise them
1 parent 4817784 commit 96f40fe

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

numpy/_array_api/_array_object.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def __abs__(self: array, /) -> array:
149149
res = self._array.__abs__()
150150
return self.__class__._new(res)
151151

152+
@np.errstate(all='ignore')
152153
def __add__(self: array, other: array, /) -> array:
153154
"""
154155
Performs the operation __add__.
@@ -196,6 +197,7 @@ def __dlpack_device__(self: array, /) -> Tuple[IntEnum, int]:
196197
"""
197198
Performs the operation __dlpack_device__.
198199
"""
200+
# Note: device support is required for this
199201
res = self._array.__dlpack_device__()
200202
return self.__class__._new(res)
201203

@@ -219,6 +221,7 @@ def __float__(self: array, /) -> float:
219221
res = self._array.__float__()
220222
return res
221223

224+
@np.errstate(all='ignore')
222225
def __floordiv__(self: array, other: array, /) -> array:
223226
"""
224227
Performs the operation __floordiv__.
@@ -434,6 +437,7 @@ def __matmul__(self: array, other: array, /) -> array:
434437
res = self._array.__matmul__(other._array)
435438
return self.__class__._new(res)
436439

440+
@np.errstate(all='ignore')
437441
def __mod__(self: array, other: array, /) -> array:
438442
"""
439443
Performs the operation __mod__.
@@ -444,6 +448,7 @@ def __mod__(self: array, other: array, /) -> array:
444448
res = self._array.__mod__(other._array)
445449
return self.__class__._new(res)
446450

451+
@np.errstate(all='ignore')
447452
def __mul__(self: array, other: array, /) -> array:
448453
"""
449454
Performs the operation __mul__.
@@ -488,6 +493,7 @@ def __pos__(self: array, /) -> array:
488493
res = self._array.__pos__()
489494
return self.__class__._new(res)
490495

496+
@np.errstate(all='ignore')
491497
def __pow__(self: array, other: array, /) -> array:
492498
"""
493499
Performs the operation __pow__.
@@ -523,6 +529,7 @@ def __setitem__(self, key, value, /):
523529
res = self._array.__setitem__(key, asarray(value)._array)
524530
return self.__class__._new(res)
525531

532+
@np.errstate(all='ignore')
526533
def __sub__(self: array, other: array, /) -> array:
527534
"""
528535
Performs the operation __sub__.
@@ -533,6 +540,7 @@ def __sub__(self: array, other: array, /) -> array:
533540
res = self._array.__sub__(other._array)
534541
return self.__class__._new(res)
535542

543+
@np.errstate(all='ignore')
536544
def __truediv__(self: array, other: array, /) -> array:
537545
"""
538546
Performs the operation __truediv__.
@@ -553,6 +561,7 @@ def __xor__(self: array, other: array, /) -> array:
553561
res = self._array.__xor__(other._array)
554562
return self.__class__._new(res)
555563

564+
@np.errstate(all='ignore')
556565
def __iadd__(self: array, other: array, /) -> array:
557566
"""
558567
Performs the operation __iadd__.
@@ -564,6 +573,7 @@ def __iadd__(self: array, other: array, /) -> array:
564573
raise RuntimeError
565574
return self.__class__._new(res)
566575

576+
@np.errstate(all='ignore')
567577
def __radd__(self: array, other: array, /) -> array:
568578
"""
569579
Performs the operation __radd__.
@@ -593,6 +603,7 @@ def __rand__(self: array, other: array, /) -> array:
593603
res = self._array.__rand__(other._array)
594604
return self.__class__._new(res)
595605

606+
@np.errstate(all='ignore')
596607
def __ifloordiv__(self: array, other: array, /) -> array:
597608
"""
598609
Performs the operation __ifloordiv__.
@@ -602,6 +613,7 @@ def __ifloordiv__(self: array, other: array, /) -> array:
602613
res = self._array.__ifloordiv__(other._array)
603614
return self.__class__._new(res)
604615

616+
@np.errstate(all='ignore')
605617
def __rfloordiv__(self: array, other: array, /) -> array:
606618
"""
607619
Performs the operation __rfloordiv__.
@@ -656,6 +668,7 @@ def __rmatmul__(self: array, other: array, /) -> array:
656668
res = self._array.__rmatmul__(other._array)
657669
return self.__class__._new(res)
658670

671+
@np.errstate(all='ignore')
659672
def __imod__(self: array, other: array, /) -> array:
660673
"""
661674
Performs the operation __imod__.
@@ -665,6 +678,7 @@ def __imod__(self: array, other: array, /) -> array:
665678
res = self._array.__imod__(other._array)
666679
return self.__class__._new(res)
667680

681+
@np.errstate(all='ignore')
668682
def __rmod__(self: array, other: array, /) -> array:
669683
"""
670684
Performs the operation __rmod__.
@@ -675,6 +689,7 @@ def __rmod__(self: array, other: array, /) -> array:
675689
res = self._array.__rmod__(other._array)
676690
return self.__class__._new(res)
677691

692+
@np.errstate(all='ignore')
678693
def __imul__(self: array, other: array, /) -> array:
679694
"""
680695
Performs the operation __imul__.
@@ -684,6 +699,7 @@ def __imul__(self: array, other: array, /) -> array:
684699
res = self._array.__imul__(other._array)
685700
return self.__class__._new(res)
686701

702+
@np.errstate(all='ignore')
687703
def __rmul__(self: array, other: array, /) -> array:
688704
"""
689705
Performs the operation __rmul__.
@@ -713,6 +729,7 @@ def __ror__(self: array, other: array, /) -> array:
713729
res = self._array.__ror__(other._array)
714730
return self.__class__._new(res)
715731

732+
@np.errstate(all='ignore')
716733
def __ipow__(self: array, other: array, /) -> array:
717734
"""
718735
Performs the operation __ipow__.
@@ -722,6 +739,7 @@ def __ipow__(self: array, other: array, /) -> array:
722739
res = self._array.__ipow__(other._array)
723740
return self.__class__._new(res)
724741

742+
@np.errstate(all='ignore')
725743
def __rpow__(self: array, other: array, /) -> array:
726744
"""
727745
Performs the operation __rpow__.
@@ -756,6 +774,7 @@ def __rrshift__(self: array, other: array, /) -> array:
756774
res = self._array.__rrshift__(other._array).astype(other.dtype)
757775
return self.__class__._new(res)
758776

777+
@np.errstate(all='ignore')
759778
def __isub__(self: array, other: array, /) -> array:
760779
"""
761780
Performs the operation __isub__.
@@ -765,6 +784,7 @@ def __isub__(self: array, other: array, /) -> array:
765784
res = self._array.__isub__(other._array)
766785
return self.__class__._new(res)
767786

787+
@np.errstate(all='ignore')
768788
def __rsub__(self: array, other: array, /) -> array:
769789
"""
770790
Performs the operation __rsub__.
@@ -775,6 +795,7 @@ def __rsub__(self: array, other: array, /) -> array:
775795
res = self._array.__rsub__(other._array)
776796
return self.__class__._new(res)
777797

798+
@np.errstate(all='ignore')
778799
def __itruediv__(self: array, other: array, /) -> array:
779800
"""
780801
Performs the operation __itruediv__.
@@ -784,6 +805,7 @@ def __itruediv__(self: array, other: array, /) -> array:
784805
res = self._array.__itruediv__(other._array)
785806
return self.__class__._new(res)
786807

808+
@np.errstate(all='ignore')
787809
def __rtruediv__(self: array, other: array, /) -> array:
788810
"""
789811
Performs the operation __rtruediv__.
@@ -829,7 +851,8 @@ def device(self):
829851
830852
See its docstring for more information.
831853
"""
832-
return self._array.device
854+
# Note: device support is required for this
855+
raise NotImplementedError("The device attribute is not yet implemented")
833856

834857
@property
835858
def ndim(self):

numpy/_array_api/_elementwise_functions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def abs(x: array, /) -> array:
2222
return ndarray._new(np.abs(x._array))
2323

2424
# Note: the function name is different here
25+
@np.errstate(all='ignore')
2526
def acos(x: array, /) -> array:
2627
"""
2728
Array API compatible wrapper for :py:func:`np.arccos <numpy.arccos>`.
@@ -33,6 +34,7 @@ def acos(x: array, /) -> array:
3334
return ndarray._new(np.arccos(x._array))
3435

3536
# Note: the function name is different here
37+
@np.errstate(all='ignore')
3638
def acosh(x: array, /) -> array:
3739
"""
3840
Array API compatible wrapper for :py:func:`np.arccosh <numpy.arccosh>`.
@@ -43,6 +45,7 @@ def acosh(x: array, /) -> array:
4345
raise TypeError('Only floating-point dtypes are allowed in acosh')
4446
return ndarray._new(np.arccosh(x._array))
4547

48+
@np.errstate(all='ignore')
4649
def add(x1: array, x2: array, /) -> array:
4750
"""
4851
Array API compatible wrapper for :py:func:`np.add <numpy.add>`.
@@ -55,6 +58,7 @@ def add(x1: array, x2: array, /) -> array:
5558
return ndarray._new(np.add(x1._array, x2._array))
5659

5760
# Note: the function name is different here
61+
@np.errstate(all='ignore')
5862
def asin(x: array, /) -> array:
5963
"""
6064
Array API compatible wrapper for :py:func:`np.arcsin <numpy.arcsin>`.
@@ -66,6 +70,7 @@ def asin(x: array, /) -> array:
6670
return ndarray._new(np.arcsin(x._array))
6771

6872
# Note: the function name is different here
73+
@np.errstate(all='ignore')
6974
def asinh(x: array, /) -> array:
7075
"""
7176
Array API compatible wrapper for :py:func:`np.arcsinh <numpy.arcsinh>`.
@@ -100,6 +105,7 @@ def atan2(x1: array, x2: array, /) -> array:
100105
return ndarray._new(np.arctan2(x1._array, x2._array))
101106

102107
# Note: the function name is different here
108+
@np.errstate(all='ignore')
103109
def atanh(x: array, /) -> array:
104110
"""
105111
Array API compatible wrapper for :py:func:`np.arctanh <numpy.arctanh>`.
@@ -203,6 +209,7 @@ def ceil(x: array, /) -> array:
203209
return x
204210
return ndarray._new(np.ceil(x._array))
205211

212+
@np.errstate(all='ignore')
206213
def cos(x: array, /) -> array:
207214
"""
208215
Array API compatible wrapper for :py:func:`np.cos <numpy.cos>`.
@@ -213,6 +220,7 @@ def cos(x: array, /) -> array:
213220
raise TypeError('Only floating-point dtypes are allowed in cos')
214221
return ndarray._new(np.cos(x._array))
215222

223+
@np.errstate(all='ignore')
216224
def cosh(x: array, /) -> array:
217225
"""
218226
Array API compatible wrapper for :py:func:`np.cosh <numpy.cosh>`.
@@ -223,6 +231,7 @@ def cosh(x: array, /) -> array:
223231
raise TypeError('Only floating-point dtypes are allowed in cosh')
224232
return ndarray._new(np.cosh(x._array))
225233

234+
@np.errstate(all='ignore')
226235
def divide(x1: array, x2: array, /) -> array:
227236
"""
228237
Array API compatible wrapper for :py:func:`np.divide <numpy.divide>`.
@@ -243,6 +252,7 @@ def equal(x1: array, x2: array, /) -> array:
243252
x1, x2 = ndarray._normalize_two_args(x1, x2)
244253
return ndarray._new(np.equal(x1._array, x2._array))
245254

255+
@np.errstate(all='ignore')
246256
def exp(x: array, /) -> array:
247257
"""
248258
Array API compatible wrapper for :py:func:`np.exp <numpy.exp>`.
@@ -253,6 +263,7 @@ def exp(x: array, /) -> array:
253263
raise TypeError('Only floating-point dtypes are allowed in exp')
254264
return ndarray._new(np.exp(x._array))
255265

266+
@np.errstate(all='ignore')
256267
def expm1(x: array, /) -> array:
257268
"""
258269
Array API compatible wrapper for :py:func:`np.expm1 <numpy.expm1>`.
@@ -276,6 +287,7 @@ def floor(x: array, /) -> array:
276287
return x
277288
return ndarray._new(np.floor(x._array))
278289

290+
@np.errstate(all='ignore')
279291
def floor_divide(x1: array, x2: array, /) -> array:
280292
"""
281293
Array API compatible wrapper for :py:func:`np.floor_divide <numpy.floor_divide>`.
@@ -361,6 +373,7 @@ def less_equal(x1: array, x2: array, /) -> array:
361373
x1, x2 = ndarray._normalize_two_args(x1, x2)
362374
return ndarray._new(np.less_equal(x1._array, x2._array))
363375

376+
@np.errstate(all='ignore')
364377
def log(x: array, /) -> array:
365378
"""
366379
Array API compatible wrapper for :py:func:`np.log <numpy.log>`.
@@ -371,6 +384,7 @@ def log(x: array, /) -> array:
371384
raise TypeError('Only floating-point dtypes are allowed in log')
372385
return ndarray._new(np.log(x._array))
373386

387+
@np.errstate(all='ignore')
374388
def log1p(x: array, /) -> array:
375389
"""
376390
Array API compatible wrapper for :py:func:`np.log1p <numpy.log1p>`.
@@ -381,6 +395,7 @@ def log1p(x: array, /) -> array:
381395
raise TypeError('Only floating-point dtypes are allowed in log1p')
382396
return ndarray._new(np.log1p(x._array))
383397

398+
@np.errstate(all='ignore')
384399
def log2(x: array, /) -> array:
385400
"""
386401
Array API compatible wrapper for :py:func:`np.log2 <numpy.log2>`.
@@ -391,6 +406,7 @@ def log2(x: array, /) -> array:
391406
raise TypeError('Only floating-point dtypes are allowed in log2')
392407
return ndarray._new(np.log2(x._array))
393408

409+
@np.errstate(all='ignore')
394410
def log10(x: array, /) -> array:
395411
"""
396412
Array API compatible wrapper for :py:func:`np.log10 <numpy.log10>`.
@@ -455,6 +471,7 @@ def logical_xor(x1: array, x2: array, /) -> array:
455471
x1, x2 = ndarray._normalize_two_args(x1, x2)
456472
return ndarray._new(np.logical_xor(x1._array, x2._array))
457473

474+
@np.errstate(all='ignore')
458475
def multiply(x1: array, x2: array, /) -> array:
459476
"""
460477
Array API compatible wrapper for :py:func:`np.multiply <numpy.multiply>`.
@@ -496,6 +513,7 @@ def positive(x: array, /) -> array:
496513
return ndarray._new(np.positive(x._array))
497514

498515
# Note: the function name is different here
516+
@np.errstate(all='ignore')
499517
def pow(x1: array, x2: array, /) -> array:
500518
"""
501519
Array API compatible wrapper for :py:func:`np.power <numpy.power>`.
@@ -507,6 +525,7 @@ def pow(x1: array, x2: array, /) -> array:
507525
x1, x2 = ndarray._normalize_two_args(x1, x2)
508526
return ndarray._new(np.power(x1._array, x2._array))
509527

528+
@np.errstate(all='ignore')
510529
def remainder(x1: array, x2: array, /) -> array:
511530
"""
512531
Array API compatible wrapper for :py:func:`np.remainder <numpy.remainder>`.
@@ -538,6 +557,7 @@ def sign(x: array, /) -> array:
538557
raise TypeError('Only numeric dtypes are allowed in sign')
539558
return ndarray._new(np.sign(x._array))
540559

560+
@np.errstate(all='ignore')
541561
def sin(x: array, /) -> array:
542562
"""
543563
Array API compatible wrapper for :py:func:`np.sin <numpy.sin>`.
@@ -548,6 +568,7 @@ def sin(x: array, /) -> array:
548568
raise TypeError('Only floating-point dtypes are allowed in sin')
549569
return ndarray._new(np.sin(x._array))
550570

571+
@np.errstate(all='ignore')
551572
def sinh(x: array, /) -> array:
552573
"""
553574
Array API compatible wrapper for :py:func:`np.sinh <numpy.sinh>`.
@@ -558,6 +579,7 @@ def sinh(x: array, /) -> array:
558579
raise TypeError('Only floating-point dtypes are allowed in sinh')
559580
return ndarray._new(np.sinh(x._array))
560581

582+
@np.errstate(all='ignore')
561583
def square(x: array, /) -> array:
562584
"""
563585
Array API compatible wrapper for :py:func:`np.square <numpy.square>`.
@@ -568,6 +590,7 @@ def square(x: array, /) -> array:
568590
raise TypeError('Only numeric dtypes are allowed in square')
569591
return ndarray._new(np.square(x._array))
570592

593+
@np.errstate(all='ignore')
571594
def sqrt(x: array, /) -> array:
572595
"""
573596
Array API compatible wrapper for :py:func:`np.sqrt <numpy.sqrt>`.
@@ -578,6 +601,7 @@ def sqrt(x: array, /) -> array:
578601
raise TypeError('Only floating-point dtypes are allowed in sqrt')
579602
return ndarray._new(np.sqrt(x._array))
580603

604+
@np.errstate(all='ignore')
581605
def subtract(x1: array, x2: array, /) -> array:
582606
"""
583607
Array API compatible wrapper for :py:func:`np.subtract <numpy.subtract>`.
@@ -589,6 +613,7 @@ def subtract(x1: array, x2: array, /) -> array:
589613
x1, x2 = ndarray._normalize_two_args(x1, x2)
590614
return ndarray._new(np.subtract(x1._array, x2._array))
591615

616+
@np.errstate(all='ignore')
592617
def tan(x: array, /) -> array:
593618
"""
594619
Array API compatible wrapper for :py:func:`np.tan <numpy.tan>`.

0 commit comments

Comments
 (0)