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

Method test_ufunc_override_out

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

Source from the content-addressed store, hash-verified

3791 assert_raises(TypeError, np.multiply.at, a, a, a, a)
3792
3793 def test_ufunc_override_out(self):
3794
3795 class A:
3796 def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
3797 return kwargs
3798
3799 class B:
3800 def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
3801 return kwargs
3802
3803 a = A()
3804 b = B()
3805 res0 = np.multiply(a, b, 'out_arg')
3806 res1 = np.multiply(a, b, out='out_arg')
3807 res2 = np.multiply(2, b, 'out_arg')
3808 res3 = np.multiply(3, b, out='out_arg')
3809 res4 = np.multiply(a, 4, 'out_arg')
3810 res5 = np.multiply(a, 5, out='out_arg')
3811
3812 assert_equal(res0['out'][0], 'out_arg')
3813 assert_equal(res1['out'][0], 'out_arg')
3814 assert_equal(res2['out'][0], 'out_arg')
3815 assert_equal(res3['out'][0], 'out_arg')
3816 assert_equal(res4['out'][0], 'out_arg')
3817 assert_equal(res5['out'][0], 'out_arg')
3818
3819 # ufuncs with multiple output modf and frexp.
3820 res6 = np.modf(a, 'out0', 'out1')
3821 res7 = np.frexp(a, 'out0', 'out1')
3822 assert_equal(res6['out'][0], 'out0')
3823 assert_equal(res6['out'][1], 'out1')
3824 assert_equal(res7['out'][0], 'out0')
3825 assert_equal(res7['out'][1], 'out1')
3826
3827 # While we're at it, check that default output is never passed on.
3828 assert_(np.sin(a, None) == {})
3829 assert_(np.sin(a, out=None) == {})
3830 assert_(np.sin(a, out=(None,)) == {})
3831 assert_(np.modf(a, None) == {})
3832 assert_(np.modf(a, None, None) == {})
3833 assert_(np.modf(a, out=(None, None)) == {})
3834 with assert_raises(TypeError):
3835 # Out argument must be tuple, since there are multiple outputs.
3836 np.modf(a, out=None)
3837
3838 # don't give positional and output argument, or too many arguments.
3839 # wrong number of arguments in the tuple is an error too.
3840 assert_raises(TypeError, np.multiply, a, b, 'one', out='two')
3841 assert_raises(TypeError, np.multiply, a, b, 'one', 'two')
3842 assert_raises(ValueError, np.multiply, a, b, out=('one', 'two'))
3843 assert_raises(TypeError, np.multiply, a, out=())
3844 assert_raises(TypeError, np.modf, a, 'one', out=('two', 'three'))
3845 assert_raises(TypeError, np.modf, a, 'one', 'two', 'three')
3846 assert_raises(ValueError, np.modf, a, out=('one', 'two', 'three'))
3847 assert_raises(ValueError, np.modf, a, out=('one',))
3848
3849 def test_ufunc_override_where(self):
3850

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
assert_Function · 0.90
assert_raisesFunction · 0.90
AClass · 0.70
BClass · 0.70

Tested by

no test coverage detected