Skip to content

Raise warnings when operations go wrong but don't fail completely #3971

Description

@jl-wynen

Originally posted in #3965 (review)

NumPy flags a number of problems in array operations such as overflow, underflow and division by zero. It would be helpful if Scipp did the same to help users diagnose problems more easily.

There are two main challenges here:

Flagging problems

This would require a change to the core transform logic so that kernels can flag problems without stopping the transformation. NumPy uses global flags for this purpose and we probably need to do the same.

However, we need to make sure that this works with multi threading in Python. E.g., given

def foo(a, b):  a / b
def bar(a): a / 0

if each function runs in its own thread, a global flag in C++ might flag a division by zero in foo if the threads line up poorly.

Detecting problems

Division by zero is easy to detect. But overflow and underflow are trickier. We need to do this without too many operations as that would slow down the core loop in Scipp.

For floating point operations, we can use the tools provided by fenv.

For integers, we would ideally use the functions in stdckdint.h. But they were only added in C++26. Going by how long it took to get access to C++20/23, this might still be a while in the future. We could maybe use the C version of that header in the meantime. But that would require using a C compiler mixed in with C+.

Activity

  1. added theissue type on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions