@@ -2327,11 +2327,11 @@ def test_dot(self):
2327
2327
2328
2328
def test_dot_override (self ):
2329
2329
class A (object ):
2330
- def __numpy_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
2330
+ def __array_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
2331
2331
return "A"
2332
2332
2333
2333
class B (object ):
2334
- def __numpy_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
2334
+ def __array_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
2335
2335
return NotImplemented
2336
2336
2337
2337
a = A ()
@@ -2804,7 +2804,7 @@ def test_elide_scalar(self):
2804
2804
2805
2805
def test_ufunc_override_rop_precedence (self ):
2806
2806
# Check that __rmul__ and other right-hand operations have
2807
- # precedence over __numpy_ufunc__
2807
+ # precedence over __array_ufunc__
2808
2808
2809
2809
ops = {
2810
2810
'__add__' : ('__radd__' , np .add , True ),
@@ -2832,8 +2832,8 @@ class OtherNdarraySubclass(np.ndarray):
2832
2832
pass
2833
2833
2834
2834
class OtherNdarraySubclassWithOverride (np .ndarray ):
2835
- def __numpy_ufunc__ (self , * a , ** kw ):
2836
- raise AssertionError (("__numpy_ufunc__ %r %r shouldn't have "
2835
+ def __array_ufunc__ (self , * a , ** kw ):
2836
+ raise AssertionError (("__array_ufunc__ %r %r shouldn't have "
2837
2837
"been called!" ) % (a , kw ))
2838
2838
2839
2839
def check (op_name , ndsubclass ):
@@ -2852,8 +2852,8 @@ def check(op_name, ndsubclass):
2852
2852
def __init__ (self , * a , ** kw ):
2853
2853
pass
2854
2854
2855
- def __numpy_ufunc__ (self , * a , ** kw ):
2856
- raise AssertionError (("__numpy_ufunc__ %r %r shouldn't have "
2855
+ def __array_ufunc__ (self , * a , ** kw ):
2856
+ raise AssertionError (("__array_ufunc__ %r %r shouldn't have "
2857
2857
"been called!" ) % (a , kw ))
2858
2858
2859
2859
def __op__ (self , * other ):
@@ -2868,7 +2868,7 @@ def __rop__(self, *other):
2868
2868
bases = (object ,)
2869
2869
2870
2870
dct = {'__init__' : __init__ ,
2871
- '__numpy_ufunc__ ' : __numpy_ufunc__ ,
2871
+ '__array_ufunc__ ' : __array_ufunc__ ,
2872
2872
op_name : __op__ }
2873
2873
if op_name != rop_name :
2874
2874
dct [rop_name ] = __rop__
@@ -2908,7 +2908,7 @@ def __rop__(self, *other):
2908
2908
# integer-like?
2909
2909
assert_equal (iop (arr , obj ), "rop" , err_msg = err_msg )
2910
2910
2911
- # Check that ufunc call __numpy_ufunc__ normally
2911
+ # Check that ufunc call __array_ufunc__ normally
2912
2912
if np_op is not None :
2913
2913
assert_raises (AssertionError , np_op , arr , obj ,
2914
2914
err_msg = err_msg )
@@ -2924,7 +2924,7 @@ def test_ufunc_override_rop_simple(self):
2924
2924
# Check parts of the binary op overriding behavior in an
2925
2925
# explicit test case that is easier to understand.
2926
2926
class SomeClass (object ):
2927
- def __numpy_ufunc__ (self , * a , ** kw ):
2927
+ def __array_ufunc__ (self , * a , ** kw ):
2928
2928
return "ufunc"
2929
2929
2930
2930
def __mul__ (self , other ):
@@ -2943,7 +2943,7 @@ def __lt__(self, other):
2943
2943
return "nope"
2944
2944
2945
2945
class SomeClass2 (SomeClass , np .ndarray ):
2946
- def __numpy_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
2946
+ def __array_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
2947
2947
if ufunc is np .multiply or ufunc is np .bitwise_and :
2948
2948
return "ufunc"
2949
2949
else :
@@ -2971,17 +2971,17 @@ def __rsub__(self, other):
2971
2971
2972
2972
# obj is first, so should get to define outcome.
2973
2973
assert_equal (obj * arr , 123 )
2974
- # obj is second, but has __numpy_ufunc__ and defines __rmul__.
2974
+ # obj is second, but has __array_ufunc__ and defines __rmul__.
2975
2975
assert_equal (arr * obj , 321 )
2976
- # obj is second, but has __numpy_ufunc__ and defines __rsub__.
2976
+ # obj is second, but has __array_ufunc__ and defines __rsub__.
2977
2977
assert_equal (arr - obj , "no subs for me" )
2978
- # obj is second, but has __numpy_ufunc__ and defines __lt__.
2978
+ # obj is second, but has __array_ufunc__ and defines __lt__.
2979
2979
assert_equal (arr > obj , "nope" )
2980
- # obj is second, but has __numpy_ufunc__ and defines __gt__.
2980
+ # obj is second, but has __array_ufunc__ and defines __gt__.
2981
2981
assert_equal (arr < obj , "yep" )
2982
- # Called as a ufunc, obj.__numpy_ufunc__ is used.
2982
+ # Called as a ufunc, obj.__array_ufunc__ is used.
2983
2983
assert_equal (np .multiply (arr , obj ), "ufunc" )
2984
- # obj is second, but has __numpy_ufunc__ and defines __rmul__.
2984
+ # obj is second, but has __array_ufunc__ and defines __rmul__.
2985
2985
arr *= obj
2986
2986
assert_equal (arr , 321 )
2987
2987
@@ -2991,7 +2991,7 @@ def __rsub__(self, other):
2991
2991
assert_equal (arr - obj2 , "no subs for me" )
2992
2992
assert_equal (arr > obj2 , "nope" )
2993
2993
assert_equal (arr < obj2 , "yep" )
2994
- # Called as a ufunc, obj2.__numpy_ufunc__ is called.
2994
+ # Called as a ufunc, obj2.__array_ufunc__ is called.
2995
2995
assert_equal (np .multiply (arr , obj2 ), "ufunc" )
2996
2996
# Also when the method is not overridden.
2997
2997
assert_equal (arr & obj2 , "ufunc" )
@@ -3012,13 +3012,13 @@ def __rsub__(self, other):
3012
3012
assert_equal (obj2 * obj3 , 123 )
3013
3013
# And of course, here obj3.__mul__ should be called.
3014
3014
assert_equal (obj3 * obj2 , 123 )
3015
- # obj3 defines __numpy_ufunc__ but obj3.__radd__ is obj2.__radd__.
3015
+ # obj3 defines __array_ufunc__ but obj3.__radd__ is obj2.__radd__.
3016
3016
# (and both are just ndarray.__radd__); see #4815.
3017
3017
res = obj2 + obj3
3018
3018
assert_equal (res , 46 )
3019
3019
assert_ (isinstance (res , SomeClass2 ))
3020
3020
# Since obj3 is a subclass, it should have precedence, like CPython
3021
- # would give, even though obj2 has __numpy_ufunc__ and __radd__.
3021
+ # would give, even though obj2 has __array_ufunc__ and __radd__.
3022
3022
# See gh-4815 and gh-5747.
3023
3023
res = obj3 + obj2
3024
3024
assert_equal (res , 46 )
@@ -3027,7 +3027,7 @@ def __rsub__(self, other):
3027
3027
def test_ufunc_override_normalize_signature (self ):
3028
3028
# gh-5674
3029
3029
class SomeClass (object ):
3030
- def __numpy_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3030
+ def __array_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3031
3031
return kw
3032
3032
3033
3033
a = SomeClass ()
@@ -3044,7 +3044,7 @@ def test_numpy_ufunc_index(self):
3044
3044
# Check that index is set appropriately, also if only an output
3045
3045
# is passed on (latter is another regression tests for github bug 4753)
3046
3046
class CheckIndex (object ):
3047
- def __numpy_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3047
+ def __array_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3048
3048
return i
3049
3049
3050
3050
a = CheckIndex ()
@@ -3080,7 +3080,7 @@ def __numpy_ufunc__(self, ufunc, method, i, inputs, **kw):
3080
3080
def test_out_override (self ):
3081
3081
# regression test for github bug 4753
3082
3082
class OutClass (np .ndarray ):
3083
- def __numpy_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3083
+ def __array_ufunc__ (self , ufunc , method , i , inputs , ** kw ):
3084
3084
if 'out' in kw :
3085
3085
tmp_kw = kw .copy ()
3086
3086
tmp_kw .pop ('out' )
@@ -5213,14 +5213,14 @@ class A(np.ndarray):
5213
5213
def __new__ (cls , * args , ** kwargs ):
5214
5214
return np .array (* args , ** kwargs ).view (cls )
5215
5215
5216
- def __numpy_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
5216
+ def __array_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
5217
5217
return "A"
5218
5218
5219
5219
class B (np .ndarray ):
5220
5220
def __new__ (cls , * args , ** kwargs ):
5221
5221
return np .array (* args , ** kwargs ).view (cls )
5222
5222
5223
- def __numpy_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
5223
+ def __array_ufunc__ (self , ufunc , method , pos , inputs , ** kwargs ):
5224
5224
return NotImplemented
5225
5225
5226
5226
a = A ([1 , 2 ])
0 commit comments