E401 BUG: scalars missing __complex__ for array api compat · Issue #27305 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: scalars missing __complex__ for array api compat #27305

@Illviljan

Description

@Illviljan

Describe the issue:

I keep getting stuck trying to get tests in https://github.com/data-apis/array-api-tests to pass and the final errors are often due to numpy arrays having turned into scalars and the tests not expecting that, (https://data-apis.org/array-api/draft/API_specification/array_object.html)

Reading #26850 it seems the intention is that the scalars should support the array api spec?

Reproduce the code example:

import numpy as np
import array_api_strict as xps


# Some examples:
xps.mean(xps.asarray(4, dtype=xps.float32)).__iadd__(1)
np.mean(np.asarray(4, dtype=np.float32)).__iadd__(1) # AttributeError: 'numpy.float32' object has no attribute '__iadd__'

xps.all(xps.asarray(True, dtype=xps.bool)).__ior__(False)
np.all(np.asarray(True, dtype=np.bool)).__ior__(False)  # AttributeError: 'numpy.bool' object has no attribute '__ior__'

xps.mean(xps.asarray(4, dtype=xps.float32)).__complex__()
np.mean(np.asarray(4, dtype=np.float32)).__complex__() # AttributeError: 'numpy.float32' object has no attribute '__complex__'

Error message:

No response

Python and NumPy Versions:

import sys, numpy; print(numpy.version); print(sys.version)
2.1.0
3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:42:31) [MSC v.1937 64 bit (AMD64)]

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0