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

Inconsistent behavior for item assignment to vector arrays #457

Open
simonthor opened this issue Apr 18, 2024 · 2 comments
Open

Inconsistent behavior for item assignment to vector arrays #457

simonthor opened this issue Apr 18, 2024 · 2 comments
Labels
bug The problem described is something that must be fixed duplicate This issue or pull request already exists feature New feature or request

Comments

@simonthor
Copy link

Vector Version

1.3.1

Python Version

3.11.4

OS / Environment

Kubuntu Linux 22.04.
vector is installed using pip in a conda environment.

Describe the bug

When trying to assign certain items in a vector numpy array, the behavior is different depending on how it is done.

> v = vector.array({"E": np.arange(4), "px": np.zeros(4), "py": np.zeros(4), "pz": np.zeros(4)})
> print(v)
[(0., 0., 0., 0) (0., 0., 0., 1) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a slice:

> v[1:2] = vector.array({"E": [8], "px": [0], "py": [0], "pz": [0]})
> print(v) # Changes the item correctly
[(0., 0., 0., 0) (0., 0., 0., 8) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a boolean array:

> v[v.E > 2] = vector.array({"E": np.ones(2), "px": np.ones(2), "py": np.ones(2), "pz": np.ones(2)})
> print(v) # Does nothing and fails silently
[(0., 0., 0., 0) (0., 0., 0., 8) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a single index:

> v[1] = vector.array(dict(px=[0.0], py=[0.0], pz=[0.0], E=[3])) # Crashes
TypeError: 'MomentumObject4D' object does not support item assignment

Any additional but relevant log output

No response

@simonthor simonthor added the bug (unverified) The problem described would be a bug, but needs to be triaged label Apr 18, 2024
@Saransh-cpp Saransh-cpp added bug The problem described is something that must be fixed and removed bug (unverified) The problem described would be a bug, but needs to be triaged labels Apr 19, 2024
@Saransh-cpp
Copy link
Member

I was able to reproduce this locally. Thanks for the report! I'll look into this.

@Saransh-cpp Saransh-cpp added the feature New feature or request label May 20, 2024
@Saransh-cpp
Copy link
Member

Related to #158 - see #158 (comment) for a detailed explanation (working on this at the moment).

@Saransh-cpp Saransh-cpp added the duplicate This issue or pull request already exists label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The problem described is something that must be fixed duplicate This issue or pull request already exists feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants