Skip to content

MAINT,ENH: Use non-error functions isless, isgreater, etc. #19398

Open

Description

@seberg

The functions isless, and friends (see https://en.cppreference.com/w/c/numeric/math/isless) are C99 standardized and should be equivalent to the normal math operators but not set floating point exceptions. I expect that using these macros would remove almost all of the places where we currently set npy_clear_floatstatus_barrier().

That would both slightly speed things up (at least if errors did occur npy_clear_floatstatus_barrier is pretty slow), and just be slightly more correct not to worry set the flags in the first place.

In the long-run, I am also thinking of chaining (e.g. by numexpr), where a call to npy_clear_floatstatus_barrier could silence floating point warnings, if the ufuncs are chained in lowlevel C.

EDIT: https://www.gnu.org/software/libc/manual/html_node/FP-Comparison-Functions.html is probably a nice reference

Activity

  1. seberg commented on Jul 22, 2021

    @seberg
    MemberAuthor

    I had done this in gh-19476, but it turns out that:

    • MSVC ≤19 is incapable to optimize isnan, isfinite, isless, etc. (because they are defined in math.h), making them extremely slow in general (maybe global, link-time, optimization can safe that a bit, but I am not sure. They are compiled into a function call, instead the single CPU instruction they should be).
    • clang <10.0 seems to not honor the request properly with optimization at least.
    • Mac CI showed problem (even though it reports clang 11.0.0)? (Not sure why...)

    So: We can probably use these functions as in gh-19316, where Mac breaks correctness anyway and the MSVC slowdown is likely acceptable, but unfortunately probably not yet(?) for things like maximum/minimum.

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