diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index e17523451cfd..53c53d7c4a6b 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -697,6 +697,7 @@ def english_upper(s): Ufunc(1, 1, None, docstrings.get('numpy.core.umath.exp'), None, + TD('e', f='exp', astype={'e':'f'}), TD('f', simd=[('avx2', 'f'), ('avx512f', 'f')]), TD(inexact, f='exp', astype={'e':'f'}), TD(P, f='exp'), @@ -719,6 +720,7 @@ def english_upper(s): Ufunc(1, 1, None, docstrings.get('numpy.core.umath.log'), None, + TD('e', f='log', astype={'e':'f'}), TD('f', simd=[('avx2', 'f'), ('avx512f', 'f')]), TD(inexact, f='log', astype={'e':'f'}), TD(P, f='log'), diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index b6b68d922c46..4b26c2208638 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1936,3 +1936,31 @@ def test_nat_is_not_inf(self, nat): assert not np.isinf(nat) except TypeError: pass # ok, just not implemented + + +@pytest.mark.parametrize('ufunc', [getattr(np, x) for x in dir(np) + if isinstance(getattr(np, x), np.ufunc)]) +def test_ufunc_types(ufunc): + ''' + Check all ufuncs that the correct type is returned. Avoid + object and boolean types since many operations are not defined for + for them. + + Choose the shape so even dot and matmul will succeed + ''' + for typ in ufunc.types: + # types is a list of strings like ii->i + if 'O' in typ or '?' in typ: + continue + inp, out = typ.split('->') + args = [np.ones((3, 3), t) for t in inp] + with warnings.catch_warnings(record=True): + warnings.filterwarnings("always") + res = ufunc(*args) + if isinstance(res, tuple): + outs = tuple(out) + assert len(res) == len(outs) + for r, t in zip(res, outs): + assert r.dtype == np.dtype(t) + else: + assert res.dtype == np.dtype(out)