Skip to content

add array_namespace option to return wrapped if possible, else native #168

Closed

Description

@lucascolley

Since array_namespace(x, use_compat=None) now returns plain numpy, but released NumPy still has incompatibilities with the standard, we want to use use_compat=True in SciPy. However, since array-api-strict isn't wrapped, array_namespace throws a ValueError, so we have to use:

try:
    return array_api_compat.array_namespace(*_arrays, use_compat=True)
except ValueError:
    return array_api_compat.array_namespace(*_arrays, use_compat=None)

array-api-strict isn't special here, this goes for any standard-compliant library. It would be nice to have an option to do this without having to catch an exception. Alternatively, we could just wait until NumPy is fully compatible with the standard before making the native namespace the default, but I'm not sure how feasible that is as the standard continues to change.

x-ref scipy/scipy#21264

Activity

  1. asmeurer commented on Jul 30, 2024

    @asmeurer
    Member

    Well I think we're going to have to get rid of the "numpy 2.0 doesn't get wrapped at all" logic because there actually are some differences from the standard in NumPy 2.0 and even NumPy 2.1 (which weren't caught for some reason #167). I thought it would simplify things to not wrap NumPy 2.0 at all, but I think instead we are going to just have a separate, simpler wrapper namespace for it.

  2. added 2 commits that reference this issue on Jul 30, 2024
    7b76d17
    850ef72
  3. asmeurer commented on Jul 30, 2024

    @asmeurer
    Member

    If we do end up needing more control of this option we can update it, but for now I think this should solve your issue. #170

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions