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

Move findnz to SparseArrays module #25641

Merged
merged 2 commits into from
Jan 22, 2018
Merged

Move findnz to SparseArrays module #25641

merged 2 commits into from
Jan 22, 2018

Conversation

nalimilan
Copy link
Member

Its definition (return stored entries) only makes sense in the context of sparse arrays. Closes #24910. Part of #10593.

The first commit should be kept separate, it fixes an inconsistency spotted at #24910 (comment).

@nalimilan nalimilan added domain:arrays:sparse Sparse arrays stdlib Julia's standard library domain:search & find The find* family of functions labels Jan 19, 2018
deleteat!(V, (count+1):numnz)
I[count] = nzind[i]
V[count] = nzval[i]
count += 1
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for summing count anymore, either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I copied the SparseMatrix method too litterally.

0335175 changed the SparseMatrix method to also return stored zeros,
but it forgot to change the SparseVector method.
Its definition (return stored entries) only makes sense in the context of sparse arrays.
Copy link
Member

@Sacha0 Sacha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Thanks @nalimilan! :)

@Sacha0
Copy link
Member

Sacha0 commented Jan 20, 2018

Tangentially, the more I consider this function, the more convinced I become that Stefan's "kill it with fire" quip was spot on. What particularly bothers me is the difference in this function's behavior between dense and sparse arrays; in other words, I am not certain I could write a generally valid docstring for this function as it stands. Best! :)

@nalimilan
Copy link
Member Author

Tangentially, the more I consider this function, the more convinced I become that Stefan's "kill it with fire" quip was spot on. What particularly bothers me is the difference in this function's behavior between dense and sparse arrays; in other words, I am not certain I could write a generally valid docstring for this function as it stands. Best! :)

Yes, I was actually going to say something similar. It would make sense to deprecate the non-sparse methods in favor of find!(iszero, x), since that's exactly what they do (though they return the indices in a slightly different form). That way the difference of behavior with the sparse methods would be clear. We don't support e.g. nnz for non-sparse arrays.

@JeffBezanson JeffBezanson merged commit a6d1829 into master Jan 22, 2018
@JeffBezanson
Copy link
Sponsor Member

It looks like the doc string for findnz should be improved to clarify that it returns all stored entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays:sparse Sparse arrays domain:search & find The find* family of functions stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renaming findn and findnz?
5 participants