-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Reintroduce nnz and nonzeros #6963
Conversation
return (I, J, V) | ||
end | ||
|
||
nonzeros!(S::SparseMatrixCSC) = S.nzval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a convention to use !
for return types? Sorry that I ask but I just was not aware of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right - it is not.
I am still a little surprised that |
This would certainly be the expected behaviour. For access to the underlying data structures of |
Returning a copy might be the expected behavior, but it also makes I don't really see any benefit that these methods bring. If you're using |
The |
@mlubin I have used Just out of curiosity, @eldadHaber - Can your use case of Cc: @tkelman |
@@ -75,4 +75,10 @@ Sparse matrices support much of the same set of operations as dense matrices. Th | |||
|
|||
Return the symmetric permutation of A, which is ``A[p,p]``. A should be symmetric and sparse, where only the upper triangular part of the matrix is stored. This algorithm ignores the lower triangular part of the matrix. Only the upper triangular part of the result is returned as well. | |||
|
|||
.. function:: nonzeros!(A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got left over
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Removed it.
@ViralBShah, what's a typical use case where one would want to make a copy of |
Not sure that's a good idea, you're just moving the inconsistent treatment of zeros from A construction flag in At this point I don't see a whole lot of use for |
A.nzval is not recommended. We really need to have an api for that, or else we will be stick with the internal structure. |
I am with @mlubin and @tkelman here. At this point Of course we have similar issues with all the temporaries that are created in the arithmetic vector operations but unlike So from the user perspective "the right thing" to do is currently to use the fields of SparseMatrixCSC. This is ok if we decide that fields are part of an interface (see #4935 and #1974). But reading through both issues I don't see that there is already a conclusion about this. If we decide that only functions are the public interface and field overloading is not coming, then we would need accessor methods like e.g. Maybe we should introduce a convention that functions that accessor functions that may corrupt the state of an object should be named But joking aside I think that we need decisions on #1974 as this will affect the way Base will involve during the journey to 1.0 To this PR, I still like @mlubin 's (#5538) naming convention better as it is more explicite and circumvents the uncertainty that we have on structural and actual non-zeros. And I still do not get the pressing reason to make Matlab compatibility so important (other than 1 user beeing unhappy). But as we have talked about that already in #6769 I think it is time to just make a decision for 0.3. |
What's the concern with field access, name stability? Wanting to apply the same code to other sparse formats with potentially different field names? I doubt I'd use an API that's dramatically slower than field access when both are equally convenient. Having a non-copy field accessor function could be worth using, the concern about modification there is more or less the same as with slices, transposes, etc potentially returning views. |
@tkelman. Yes its about name stability and "good practice". It is always good to separate the interface from the implementation. Using functions for interfaces is whats currently done in Base (e.g. It is true that one could argue that the interface of SparseMatrixCSC is nothing that will be reused so that information hiding is probably not that important here. Still I think it would be good to have conventions that we follow even in cases where it is probably not so important. |
I understanding some of the reasoning behind the copy. However, knowing that I would suggest |
One choice is to leave nonzeros as is and have a separate api that returns all the internal vectors without making copies. |
I agree with @lindahua; |
|
Cool, now on to the next controversial issue :) |
I wasn't sure about that one, but wanted to try it out. I think it is best to remove it and avoid the cognitive overload. |
Alright, what else do you want? :-) |
Good point - done. |
|
||
Return a vector of the structural nonzero values in sparse matrix ``A``. This includes zeros that are explicitly stored in the sparse matrix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe indicate here that the vector has mutating access to the original values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
I'm satisfied on all of the substantial issues here. I think we're just missing deprecations from the 0.2 version of
(assuming that works correctly). Also NEWS has a mention of |
Why only |
I mean we should do it for |
That's probably right. |
@@ -320,7 +320,7 @@ Deprecated or removed | |||
|
|||
* `factorize!` is deprecated in favor of `factorize`. ([#5526]) | |||
|
|||
* `nnz` is removed. Use `countnz` or `nfilled` instead ([#5538]) | |||
* `nnz` counts the number of structural nonzeros in a sparse matrix. Use `countnz` for the actual number of nonzeros. ([#6769]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a link farther down for the issue [#5538]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the link as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more accurate to replace counts
with returns
:
nnz
returns the number of structural nonzeros ...
This method is not doing the counting.
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Deprecate nnz for StridedArray. Update documentation for structural nonzeros. Update NEWS
Anyone have remaining strong objections? |
LGTM. Thanks @ViralBShah for taking all objections into account! |
@ViralBShah I think it is great. Thanks. |
RFC: Reintroduce nnz and nonzeros
Reintroduce nnz and nonzeros as discussed in #6769
Deprecate nfilled
Deprecate nonzeros for StridedArray and BitArray
find()/findnz() over sparse matrices no longer filters out stored zeros
Should
sparse()
allow stored zeros in its input, using an optional argument? Although this discussion started withnnz
, I feel it is leading towards better clarity on treatment of stored zeros, and overall I am feeling good about that.