Skip to content

Should __array_function__ allow overriding arange, linspace, etc? #12379

@shoyer

Description

@shoyer

xref #12028 yt-project/unyt#50

NumPy has a handful of construction functions that accept scalars as arguments to control their bounds, e.g., arange, linspace, logspace and geomspace.

The general rule we've been using for __array_function__ is that it's only called on array-like arguments, so array construction functions are excluded. This makes a lot of sense for functions like np.zeros, where there's no possible way to infer the return type based merely on the shape. But for arange and linspace, we could defer to the __array_function__ overrides on the scalar arguments.

This would be particularly useful for scalar types implementing a unit system. (I believe we already support datetime64 in some of these constructors, but of course that's doable only because datetime64 is built into NumPy.)

CC @mhvk

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