-
-
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
Slow sparse() construction for matrices with lots of rows #13400
Comments
I am currently testing a new sparse implementation, which, at least for this case, is > 50x faster for this case (at least on my machine), using the techniques I described in my the comments in #12998, (which unfortunately have now been deleted). I've also written some improved code to benchmark various sparse operations, based on the code from @mb1234 (#12981 (comment)). |
Why don't you submit a PR, if this fits with the existing code and data structures? |
I will, as soon as I have it in a good state. |
I have another question - currently, I build a work vector with the indices of all the non-zero entries in V, Again, thanks in advance for any suggestions. |
I am aware the performance with sort is not what one hopes for, which is why we switched to the current implementation. There are probably special cases that could have a different implementation. I am open to int32 by default, but not in this issue or PR. We can do a separate issue. |
Making integer sizes depend on values of the input indices is not type stable, that's a nonstarter. It should be using the integer type of the inputs to determine the integer type of the output, promoting to the largest common integer size to avoid needing multiple separate integer type parameters. |
I raised the question in the google-group whether sparse matrices need to be parameterized at all by Ti. |
Parameterizing them by Ti is exactly how you achieve what you're asking for of using different integer types for the indices. |
No, not really. For example, if you have 1000000 rows and 100 columns, you could pass input vectors Vector{Int32} for I, and Vector{Int8} for J. The way it currently is, it forces them both to be Int32. |
SparseMatrixCSC could hypothetically be parameterized by different integer types for the rows vs the columns, but that doesn't strike me as a necessary complication. You can always make your own version of the data structure that does whatever you want it to. |
Also, it doesn't seem at all consistent with dense arrays. For dense arrays, things aren't parameterized by the types of the rows and columns that can be used to index them.
I'm not sure, but I'll benchmark, if that parameterization really improves performance, or just causes additional code to be generated. |
Here are my current results:
|
We are not going to change the parametrization of row and column indices for SparseMatrixCSC. Despite my saying that this is not the discussion forum for that matter - I see that is exactly what happened here. Let's keep this discussion to the issue at hand, and avoid tangents. In order to keep my sanity, I will delete tangential comments. We can review all this in the PR once you have it ready, and hopefully it does not degrade performance in other cases. If it uniformly improves performance everywhere, I for one, will not be complaining. |
Are there already any suites of performance tests for sparse arrays? |
Look at the sparse matrix collection: https://www.cise.ufl.edu/research/sparse/matrices/ (https://github.com/JuliaSparse/MatrixMarket.jl) |
There are some performance tests in |
@mlubin Thanks for the pointers - it looks like I'll need to adapt the MatrixMarket.jl code, because I don't want the arrays already made, I want to read in the data for the sparse arrays in coordinate format (basically, do everything in MatrixMarket.jl except the call to |
@ScottPJones, a pretty decent test would be to take the matrices in CSC form, transpose them, run findnz, and then reconstruct |
Wouldn't they be in sorted order though if I did that? |
Sorted by rows, not columns though |
But within the rows, aren't the columns also sorted? |
Now that we have real sparse vectors, this is no longer an issue. Also is twice as fast as before. We should find more realistic test cases to speed up performance of such cases. Cc @Sacha0 |
Is it being tracked in BaseBenchmarks? if not it should be added there |
Cases like |
This is slow mainly because a CSR data structure is created that allocates a vector of size 100 million, before creating the CSC.
The text was updated successfully, but these errors were encountered: