Skip to content

dtype signature for arithmetic is not fixed #6240

@shoyer

Description

@shoyer

NumPy operations generally follow the rule that the output dtype/shape is a deterministic function of the inputs dtype/shape.

However, binary arithmetic with 0d arrays appears to be an exception to these rules. Consider:

np.array(12).dtype # int64
np.array(4625196817309499392).dtype # int64
(np.array([[123]], dtype=np.float32) + np.array(12)).dtype # float32
(np.array([[123]], dtype=np.float32) + np.array(4625196817309499392)).dtype # float64

Basically, whether the result is float32 depends on the size of the scalar argument.

I can see why this would be desirable for operations with Python scalars (e.g., array + 1), but when the 0d/scalar argument is already typed this is highly surprising.


EDIT seberg: This is basically what NEP 50 is about.

Metadata

Metadata

Assignees

No one assigned

    Labels

    62 - Python APIChanges or additions to the Python API. Mailing list should usually be notified.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions