MCPcopy Create free account
hub / github.com/numpy/numpy / test_ufunc_override

Method test_ufunc_override

numpy/core/tests/test_umath.py:3219–3243  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3217 assert_raises_regex(TypeError, '2 required positional', np.sum, a)
3218
3219 def test_ufunc_override(self):
3220 # check override works even with instance with high priority.
3221 class A:
3222 def __array_ufunc__(self, func, method, *inputs, **kwargs):
3223 return self, func, method, inputs, kwargs
3224
3225 class MyNDArray(np.ndarray):
3226 __array_priority__ = 100
3227
3228 a = A()
3229 b = np.array([1]).view(MyNDArray)
3230 res0 = np.multiply(a, b)
3231 res1 = np.multiply(b, b, out=a)
3232
3233 # self
3234 assert_equal(res0[0], a)
3235 assert_equal(res1[0], a)
3236 assert_equal(res0[1], np.multiply)
3237 assert_equal(res1[1], np.multiply)
3238 assert_equal(res0[2], '__call__')
3239 assert_equal(res1[2], '__call__')
3240 assert_equal(res0[3], (a, b))
3241 assert_equal(res1[3], (b, b))
3242 assert_equal(res0[4], {})
3243 assert_equal(res1[4], {'out': (a,)})
3244
3245 def test_ufunc_override_mro(self):
3246

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
AClass · 0.70
viewMethod · 0.45

Tested by

no test coverage detected