MCPcopy Index your code
hub / github.com/numpy/numpy / test_gufunc_override

Method test_gufunc_override

numpy/_core/tests/test_umath.py:3987–4015  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3985 np.add(greedy, 1, out=opt_out)
3986
3987 def test_gufunc_override(self):
3988 # gufunc are just ufunc instances, but follow a different path,
3989 # so check __array_ufunc__ overrides them properly.
3990 class A:
3991 def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
3992 return self, ufunc, method, inputs, kwargs
3993
3994 inner1d = ncu_tests.inner1d
3995 a = A()
3996 res = inner1d(a, a)
3997 assert_equal(res[0], a)
3998 assert_equal(res[1], inner1d)
3999 assert_equal(res[2], '__call__')
4000 assert_equal(res[3], (a, a))
4001 assert_equal(res[4], {})
4002
4003 res = inner1d(1, 1, out=a)
4004 assert_equal(res[0], a)
4005 assert_equal(res[1], inner1d)
4006 assert_equal(res[2], '__call__')
4007 assert_equal(res[3], (1, 1))
4008 assert_equal(res[4], {'out': (a,)})
4009
4010 # wrong number of arguments in the tuple is an error too.
4011 assert_raises(TypeError, inner1d, a, out='two')
4012 assert_raises(TypeError, inner1d, a, a, 'one', out='two')
4013 assert_raises(TypeError, inner1d, a, a, 'one', 'two')
4014 assert_raises(ValueError, inner1d, a, a, out=('one', 'two'))
4015 assert_raises(ValueError, inner1d, a, a, out=())
4016
4017 def test_ufunc_override_with_super(self):
4018 # NOTE: this class is used in doc/source/user/basics.subclassing.rst

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
assert_raisesFunction · 0.90
AClass · 0.70

Tested by

no test coverage detected