8000 ENH: Array API standard and Numpy compatibility · Issue #21135 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to conten 6486 t
ENH: Array API standard and Numpy compatibility #21135
Open
@vnmabus

Description

@vnmabus

Proposed new feature or change:

I was testing how to add support for the array API standard to a small project of mine. However, I also wanted to remain compatible with Numpy ndarray, as it is what everyone uses right now. However, the differences in the API between the standard and ndarray, and the decision to conform to the minimal implementation of the standard, make really difficult to support both use cases with the same code.

For example, in order to create a copy of the input array, which should be a simple thing to do, using the array standard I would need to call x = xp.asarray(x, copy=True). However, when I receive a numpy ndarray I fall back to xp = np, and np.asarray does not have the copy parameter.

I can't just convert the ndarray to Array, both because I would be returning a different type than the input type, and because Array does not allow the object dtype, and I explicitly allow ndarrays containing Fraction or Decimal objects.

The ideal choice would be either to make the basic Numpy ndarray functions compatible with the standard, or to expose an advanced version of the array_api that deals directly with ndarray objects and support all Numpy functionalities in a manner compatible with the standard. Otherwise, making existing code compatible with both ndarray and the API standard will require a lot of effort and duplicated code to accommodate both.

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

      0