8000 BUG: exp and log cast float16 to float32 · Issue #13493 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: exp and log cast float16 to float32 #13493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
toslunar opened this issue May 7, 2019 · 8 comments · Fixed by #13495
Closed

BUG: exp and log cast float16 to float32 #13493

toslunar opened this issue May 7, 2019 · 8 comments · Fixed by #13495

Comments

@toslunar
Copy link
Contributor
toslunar commented May 7, 2019

After #13134 is merged, np.exp and np.log return float32 arrays for float16 inputs. Is the change intended? I could not find docs for it (https://www.numpy.org/devdocs/reference/generated/numpy.exp.html), while it is documented that np.sum casts ints to the default platform integer.

Reproducing code example:

import numpy as np
print(np.exp(np.array([1, 2], np.float16)).dtype)  # => float32
print(np.log(np.array([1, 2], np.float16)).dtype)  # => float32

Numpy/Python version information:

1.17.0.dev0+64b3e67 3.7.1 (default, Nov  6 2018, 21:02:07)
[Clang 10.0.0 (clang-1000.10.44.4)]
@charris charris added this to the 1.17.0 release milestone May 7, 2019
@charris
Copy link
Member
charris commented May 7, 2019

Looks like an unintended change. @r-devulap @mattip Thoughts? Maybe we need some tests...

@mattip
Copy link
Member
mattip commented May 7, 2019

Adding tests and looking for a fix

@r-devulap
Copy link
Member

Looking into it ..

@seberg
Copy link
Member
seberg commented May 7, 2019

I am sure you already got it, but it will be because of the linear search of the loops, if the "f,f->f" loops are registered first, they are found instead of the "e,e->e" loops.

@seberg
Copy link
Member
seberg commented May 7, 2019

Sorry for the spam. (compare also np.sqrt which currently has a funny loop duplication, but not this issue).

@mattip
Copy link
Member
mattip commented May 7, 2019

I thought changing the type to TD('f', astype={'e':'f'}, simd=[('avx2', 'f'), ('avx512f', 'f')]) (adding the astype kwarg) would have solved it, but the test is still failing. Somehow the simd part is not respecting the astype

@mattip
Copy link
Member
mattip commented May 7, 2019

Got it, need to not use simd on 'e' which makes sense

@mattip mattip changed the title exp and log cast float16 to float32 BUG: exp and log cast float16 to float32 May 7, 2019
@r-devulap
Copy link
Member

that was quick! thank you @mattip :)

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

Successfully merging a pull request may close this issue.

5 participants
0