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

Avoid making a copy of coords #296

Merged
merged 1 commit into from
Oct 17, 2019
Merged

Conversation

eric-wieser
Copy link
Contributor

Coords is not modified anywhere in this class, so we probably do not need to copy it.

This also would allow for identity short-cuts when performing operations on sparse arrays with the same sparsity pattern.

Coords is not modified anywhere in this class, so we probably do not need to copy it.

This also would allow for identity short-cuts when performing operations on sparse arrays with the same sparsity pattern.
@codecov
Copy link

codecov bot commented Oct 17, 2019

Codecov Report

Merging #296 into master will not change coverage.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master     #296   +/-   ##
=======================================
  Coverage   93.27%   93.27%           
=======================================
  Files          15       15           
  Lines        2036     2036           
=======================================
  Hits         1899     1899           
  Misses        137      137

@hameerabbasi hameerabbasi merged commit d9ed64d into pydata:master Oct 17, 2019
@hameerabbasi
Copy link
Collaborator

Thanks, @eric-wieser!

@eric-wieser
Copy link
Contributor Author

eric-wieser commented Oct 17, 2019

Worth noting that bad things could happen if anyone is doing something that mutates coords, such as:

coords = np.zeros((3, 200), np.intp)
s = COO(coords=coords, ...)
coords[...] = 0  # !!!

This doesn't seem particularly likely though, and the following was already not ok anyway:

coords = np.zeros((3, 200), np.intp)
s = COO(coords=coords, ...)
s.coords[...] = 0  # !!!

@hameerabbasi
Copy link
Collaborator

Yes, we don't follow that pattern anywhere in our code, and I'm fairly sure others don't either. Anyway, thanks for noting this.

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

Successfully merging this pull request may close these issues.

2 participants