Skip to content

TST: Add tests for FP16 umath functions#21954

Merged
mattip merged 2 commits into
numpy:mainfrom
r-devulap:fp16-math-tests
Aug 4, 2022
Merged

TST: Add tests for FP16 umath functions#21954
mattip merged 2 commits into
numpy:mainfrom
r-devulap:fp16-math-tests

Conversation

@r-devulap

Copy link
Copy Markdown
Member

Adding tests for comprehensive coverage of float16 umath functions.

Comment thread numpy/core/tests/test_umath_accuracy.py Outdated
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linting

Suggested change
assert_array_max_ulp(ufunc(datafp16), ufunc(datafp32), maxulp=1, dtype=np.float16)
assert_array_max_ulp(
ufunc(datafp16), ufunc(datafp32), maxulp=1, dtype=np.float16)

@mattip

mattip commented Jul 9, 2022

Copy link
Copy Markdown
Member

There is a failing test in cygwin.

for value in [np.inf, -np.inf]:
for dt in ['e', 'f', 'd']:
assert_raises(FloatingPointError, callable,
np.array([value], dtype=dt))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you refactor this as a parameterized test?

np.log2(arr)
np.log10(arr)
np.arccosh(arr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you refactor this into a parameterized test

@mattip mattip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. These tests need a good refactoring, this might be a nice task for a sprint. I noted two that it might be nice to fix already in this PR, if you have time.

@mattip mattip merged commit 5028e40 into numpy:main Aug 4, 2022
@mattip

mattip commented Aug 4, 2022

Copy link
Copy Markdown
Member

Thanks @r-devulap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants