Skip to content

BUG: exp and log cast float16 to float32 #13493

Closed

Description

@toslunar

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)]

Activity

  1. added this to the milestone on May 7, 2019
  2. charris commented on May 7, 2019

    @charris
    Member

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

  3. mattip commented on May 7, 2019

    @mattip
    Member

    Adding tests and looking for a fix

  4. r-devulap commented on May 7, 2019

    @r-devulap
    Member

    Looking into it ..

  5. seberg commented on May 7, 2019

    @seberg
    Member

    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.

  6. seberg commented on May 7, 2019

    @seberg
    Member

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

  7. mattip commented on May 7, 2019

    @mattip
    Member

    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

  8. mattip commented on May 7, 2019

    @mattip
    Member

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

  9. changed the title [-]exp and log cast float16 to float32[/-] [+]BUG: exp and log cast float16 to float32[/+] on May 7, 2019
  10. r-devulap commented on May 7, 2019

    @r-devulap
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions