-
-
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
nnz and nonzeros #6769
Comments
Sorry about this. You can add the following to your code:
and then you won't need to change every use. Wrapping this in Personally I dislike the decision to allow explicit zeros in sparse matrices, but I think we should bring back the definition of |
I find myself wanting to use nnz every once in a while. While we can retain stored zeros, it would be nice to have nnz and nonzeros. |
My problem is not that changes are done (I'm also not a fan of this change but this is not a big deal). My request for the future, please
Thanks |
Unless Julia has version 1.0 I don't see the issue when the API is evolving. Yes this can be painful but trying to be backward compatible in all the 0.x releases will not lead to a consistent 1.0 release. We all know that the documentation can be improved but this is a community project. There is nobody you can blame because of missing / wrong documentation. The project lives from participation. Independently of this specific issues I think there will be more breaking changes on the way to 1.0. If this is not ok for you (which is absolutely understandable) you might better try a programming environment that is more stable (e.g. Matlab). |
Please continue to file issues like this for specific changes that cause problems. There is always a chance something got removed by mistake, or that we will change our minds.
|
I think we just changed the method signature for |
Yes, but there still should have been a deprecation warning or error for the removed functionality. It was an oversight. |
And a highlight of not-very-good test coverage for sparse matrices. When this goes back in it should have a test so accidental removal without a deprecation gets caught in the future. |
Well, the removal wasn't accidental. The tests were updated, but not the deprecations. Better test coverage would of course help in general with this kind of thing though. |
Nnz does have a deprecation. That is how I keep getting reminded often that I like the name. Perhaps nonzeros may have been missed. Anyways, I will revisit this would matter soon and iron out the issues. |
@tkelman You are certainly right about the lack of tests and coverage for sparse matrices. Hoping to significantly improve sparse matrix support over the next few weeks. |
I don't think we should restore Sorry @eldadHaber for the churn. The deprecation of |
Rereading the comments in #6769, I'll defer to @JeffBezanson if the consensus is that it's better to silently change the performance of |
My view is based on looking at the other |
Right, it's not a drop in replacement, so the deprecation calls |
It's an application of the principle of least surprise. |
I consider the meaning of the operation primary, not its performance. Is it the case that knowing the actual number of !=0 elements is not useful, and 90% of the time people actually want the storage size? I suspect not, but if so then I might change my mind. |
In my experience when writing linear algebra operations with sparse matrices, |
Maybe @eldadHaber can comment on how he uses |
I have a somewhat different perspective about nnz. As we teach in any numerical analysis course, zero is not really 0. For real matrices So I fail to see what is the fuss about this command. |
It seems that this perspective falls under the |
I try to say that counting nonzeros (for real and complex matrices) does not make sense anyway. Sure we can have this functionality but it is misleading. If A has real values, most around 1 and 10% of the values are smaller than 1e-16 then you still report these values as nonzeros. |
@eldadHaber tolerancing and small numerical values are a separate question, that applies to any operation involving floating point numbers. Sparse algorithms are written in such a way that explicitly stored zero values don't change the output result (assuming you don't run into any overflow or nan). I want the storage size when I'm writing a sparse algorithm - when explicit zeros need to be there, it's almost always for matrix structural reasons. For example Pardiso requires storage to already exist for elements on the diagonal - ideally these would be stored zeros when the language allows for them, but the Matlab interface to Pardiso requires hacky inaccurate workarounds like adding The Matlab interface to Ipopt is another case of this. The linear solver used within Ipopt, like the majority of sparse direct algorithms, separates the structure-based symbolic factorization allocation step from the value-based numerical factorization step. You need to evaluate the sparse Jacobian and Hessian matrices at every iteration, with the same sparsity structure but varying nonzero values. What happens if one of the "structurally nonzero" elements happens to have a value of exactly zero at some intermediate iteration? If your language automatically removes zeros from sparse matrices, you have to account for this by making a copy of the entire sparse matrix data structure at every iteration to put the nonzeros in the proper place. Bad times. |
Thanks, that perspective is very helpful. In that case maybe we should use the general |
There was a lot of discussion on this in #5538, and I agree and have been arguing that |
I think that the tolerance should be a used choice. I'm trying to construct an example to demonstrate some of these issue |
It would make sense to add a What about |
@eldadHaber, just so you're aware: the "fuss" over this command arose because we, unlike Matlab, now allow you to store zeros in a sparse matrix. Check out the implications (following code is Matlab):
Notice the second timing is one hundred fold longer than the first: if you set a non-zero entry to zero, Matlab actually copies the entire data for the matrix, deleting that one from memory. That's really expensive. Matlab does this because it doesn't allow you to have any stored value of a sparse matrix be identically zero. In contrast, we allow stored zeros. That will* make this kind of thing infinitely more efficient. But that means there's a difference between the amount of storage required and how many entries are not identically zero. Given that matlab only has the But breaking old code is a no-no, and usually we are reasonably good about avoiding that because of the deprecation framework. But it seems to have failed in this case. *Currently it looks like |
You seem to be stuck in a posting loop, @jiahao. |
I am ok with either option 1 or 2. Option 3 is going to cause semantic inconsistencies, and a definitely no-go. |
Sorry, there appears to be a problem with my connection. |
What if we hedge this by renaming |
I'd vote for |
Option 1 is the right one I feel. For dense arrays, those methods can give suggestions to the user. |
Giving |
This is now officially the most important (commented) open Julia issue :-) It seems that people agree that But in any case, I don't see this issue a blocker for 0.3. I see it more as a proof that we have to shrink base and move these naming discussions into a standard library that potentially could be even decoupled from core/base Julia (not necessary technically but at least conceptually) |
Ah so I'll add some noise too. As a casual sparse matrix user, I think using |
We went with |
Maybe |
Deprecate nfilled Deprecate nonzeros for StridedArray and BitArray find()/findnz() over sparse matrices no longer filters out stored zeros
Deprecate nfilled Deprecate nonzeros for StridedArray and BitArray find()/findnz() over sparse matrices no longer filters out stored zeros Update documentation for structural nonzeros.
Deprecate nfilled Deprecate nonzeros for StridedArray and BitArray find()/findnz() over sparse matrices no longer filters out stored zeros Update documentation for structural nonzeros.
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Update documentation for structural nonzeros.
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Update documentation for structural nonzeros.
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Update documentation for structural nonzeros.
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Deprecate nnz for StridedArray. Update documentation for structural nonzeros. Update NEWS
Deprecate nfilled for SparseMatrixCSC. Deprecate nonzeros for StridedArray and BitArray. Deprecate nnz for StridedArray. Update documentation for structural nonzeros. Update NEWS
Fixed by 8879b88 |
Someone has decided to change nnz and to remove the nonzeros command.
I find this very unacceptable!
It is a bad practice to not allow for backward compatibility.
Many of our codes use these commands and we have to go and replace them in all our previous versions.
We are investing a considerable amount of time, trying to develop codes in julia for geophysical inversion and truly believe that it is the way to go.
If new julia versions are not going to be backward compatible we will need to rethink
our development.
Please think about this whenever you want to retire a command
The text was updated successfully, but these errors were encountered: