Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: unnecessary copy on assignment #28070

Open
DIsrael-LANL opened this issue Dec 27, 2024 · 2 comments
Open

BUG: unnecessary copy on assignment #28070

DIsrael-LANL opened this issue Dec 27, 2024 · 2 comments
Labels

Comments

@DIsrael-LANL
Copy link

DIsrael-LANL commented Dec 27, 2024

Describe the issue:

For assignment using __setitem__, numpy is calling the __array__ method on the value with a copy=True. This can be seen by running the code example.

Reproduce the code example:

import numpy

class MyThing(object):
    def __array__(self, dtype=None, copy=None):
        print(f"MyThing.__array__(dtype={dtype}, copy={copy})")
        return numpy.ones((5, 5))

u = numpy.zeros((5, 5))
v = MyThing()

u[...] = v

Error message:

No response

Python and NumPy Versions:

2.2.1
3.13.1 | packaged by conda-forge | (main, Dec 5 2024, 21:09:18) [Clang 18.1.8 ]

Runtime Environment:

No response

Context for the issue:

This additional copy on a common operation will be extremely inefficient.

@ngoldbaum
Copy link
Member

The issue description says you're using an old NumPy version - do you still the same behavior on the most recent release?

@DIsrael-LANL
Copy link
Author

Sorry, yes, I just tested for 2.2.1 (and update my report). Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants