diff options
author | Matteo Raso <matteo_luigi_raso@protonmail.com> | 2023-01-21 20:20:30 -0500 |
---|---|---|
committer | Matteo Raso <matteo_luigi_raso@protonmail.com> | 2023-01-21 20:20:30 -0500 |
commit | ade008bf5fba3cbc43ffbdf5ee261953a8a71a3a (patch) | |
tree | 9cc7aea00eed8ecba174c7d9dabb9059c22309d0 /numpy/lib/tests | |
parent | 88cdaa21aea87ec7d56d1d583500ab2659a5e65e (diff) | |
download | numpy-ade008bf5fba3cbc43ffbdf5ee261953a8a71a3a.tar.gz |
ENH: Enabled use of numpy.vectorize as decorator (#9477)
Most of this code comes from PR-9593, but with the default value for pyfunc
being numpy._NoValue instead of None, no override of __new__, and no effort
to make subclassing possible.
Co-Authored-By: Michael Lamparski <diagonaldevice@gmail.com>
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 69e4c4848..169484a09 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1788,6 +1788,36 @@ class TestVectorize: assert f2.__name__ == 'f2' + def test_decorator(self): + @vectorize + def addsubtract(a, b): + if a > b: + return a - b + else: + return a + b + + r = addsubtract([0, 3, 6, 9], [1, 3, 5, 7]) + assert_array_equal(r, [1, 6, 1, 2]) + + def test_signature_otypes_decorator(self): + @vectorize(signature='(n)->(n)', otypes=['float64']) + def f(x): + return x + + r = f([1, 2, 3]) + assert_equal(r.dtype, np.dtype('float64')) + assert_array_equal(r, [1, 2, 3]) + assert f.__name__ == 'f' + + def test_positional_regression_9477(self): + # This supplies the first keyword argument as a positional, + # to ensure that they are still properly forwarded after the + # enhancement for #9477 + f = vectorize((lambda x: x), ['float64']) + r = f([2]) + assert_equal(r.dtype, np.dtype('float64')) + + class TestLeaks: class A: iters = 20 |