diff options
| author | Raghuveer Devulapalli <raghuveer.devulapalli@intel.com> | 2022-05-23 14:44:23 -0700 |
|---|---|---|
| committer | Raghuveer Devulapalli <raghuveer.devulapalli@intel.com> | 2022-07-27 12:26:48 -0700 |
| commit | df168ac05b0bd925f858dec101ddfa1ed29ec973 (patch) | |
| tree | 949c3b846e7588b48eb023698d63b48a6c4420c2 | |
| parent | 6e1557900da3c2cc8455449e7e76b07f7c36b32a (diff) | |
| download | numpy-df168ac05b0bd925f858dec101ddfa1ed29ec973.tar.gz | |
TST: Add accuracy tests for FP16 umath functions
| -rw-r--r-- | numpy/core/tests/test_umath_accuracy.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/tests/test_umath_accuracy.py b/numpy/core/tests/test_umath_accuracy.py index 3d4d5b5aa..6ee4d2fee 100644 --- a/numpy/core/tests/test_umath_accuracy.py +++ b/numpy/core/tests/test_umath_accuracy.py @@ -8,6 +8,11 @@ from numpy.testing import assert_array_max_ulp from numpy.testing._private.utils import _glibc_older_than from numpy.core._multiarray_umath import __cpu_features__ +UNARY_UFUNCS = [obj for obj in np.core.umath.__dict__.values() if + isinstance(obj, np.ufunc)] +UNARY_OBJECT_UFUNCS = [uf for uf in UNARY_UFUNCS if "O->O" in uf.types] +UNARY_OBJECT_UFUNCS.remove(getattr(np, 'invert')) + IS_AVX = __cpu_features__.get('AVX512F', False) or \ (__cpu_features__.get('FMA3', False) and __cpu_features__.get('AVX2', False)) # only run on linux with AVX, also avoid old glibc (numpy/numpy#20448). @@ -59,3 +64,12 @@ class TestAccuracy: outval = outval[perm] maxulperr = data_subset['ulperr'].max() assert_array_max_ulp(npfunc(inval), outval, maxulperr) + + @pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS) + def test_validate_fp16_transcendentals(self, ufunc): + with np.errstate(all='ignore'): + arr = np.arange(65536, dtype=np.int16) + datafp16 = np.frombuffer(arr.tobytes(), dtype=np.float16) + datafp32 = datafp16.astype(np.float32) + assert_array_max_ulp(ufunc(datafp16), ufunc(datafp32), + maxulp=1, dtype=np.float16) |
