-
-
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
A keepzeros option for sparse(I, J, V) #12605
Comments
Thanks for raising this issue @matthieugomez, please continue the discussion at #9906 and #9928. |
We could have an option to |
Why could not zeros always be retained? This is the current behavior for I = [1, 2]
V = [0, 1]
M = sparsevec(I, V)
#2x1 sparse matrix with 2 Int64 entries:
# [1, 1] = 0
# [2, 1] = 1 The other solution, as you say, is to add an option to I don't think my issue is related to #9906 - I'm perfectly happy to work on the internal representation using |
The |
I am reopening this issue to track the |
This is not an accurate description of the data structure. Many of the operations remove zeros, but not all, and there are corner cases as with |
Like I clearly said, the cases where the zeros don't get squeezed out are bugs - that is not the design. The data structure does not care what you store in it, but the operations are all designed to squeeze out zeros. |
And the conclusion in #9928 from pretty much all heavy users of sparse matrices is that we want better support for stored zeros, not to work harder to remove them. The design should shift away from Matlab and closer to SciPy, but with adjustments anywhere we think SciPy's behavior is inconsistent and we could do better. It's a little bit like type stability actually - whether an entry has storage allocated for it in the sparse matrix output from many mathematical routines really shouldn't depend on the numerical values, it should depend primarily on the nonzero structures of its inputs. This is far more amenable to inner-loop performance-critical calculations since it's much more predictable than allocating a differently-sized array when certain numerical elements happen to exactly equal zero. |
Agreed with @tkelman. It would be much easier to ignore stored zeros in most routines, and provide a |
We have an unexported function called |
I am fine with the proposal - I just don't want to do it piecemeal. In 0.5, we can update the whole implementation in one shot. |
+1 |
Sounds like a plan. |
This can be closed now? |
sparse
currently consider zeros element in V as structural zerosThis means the sparsity structure of M depends on the values of V, and not only of the pair (I, J). So there is no way to initialize a sparse matrix with the "correct" sparsity structure, independently of its values V. This is problematic since it's inefficient to modify the structure of a sparse matrix.
Why can't
sparse
consider zeros element in V as non structural zeros? I'm not sure how other programming languages handle this situation so I'm looking for some feedback before making a pull request.The text was updated successfully, but these errors were encountered: