Skip to content

BUG: __iadd__() for numpy.array_api arrays does not follow negative zeros special case #21211

@honno

Description

@honno

Describe the issue:

The Array API spec requires __add__(), and by extension __iadd__(), to output a negative 0 when both operands are negative 0. NumPy currently follows this special case for __add__(), but not for __iadd__(). cc @asmeurer

(I'll have a look at fixing this later.)

Reproduce the code example:

In [4]: x1 = xp.asarray(-0.)

In [5]: x2 = xp.asarray(-0.)

In [6]: x1 + x2
Out[6]: Array(-0., dtype=float64)

In [7]: x1 += x2

In [8]: x1
Out[8]: Array(0., dtype=float64)  # should be -0.

Error message:

No response

NumPy/Python version information:

1.22.3 3.8.12 (default, Mar 13 2022, 19:12:08)
[GCC 9.4.0]

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