-
-
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
Refactoring: Use accessor methods when manipulating sparse matrices/vectors #32953
Conversation
Thanks. This is fantastic! Let me know when good to merge. Can you do a quick test to ensure no performance regressions have crept in? |
I did all I wanted to do this in PR. Please merge it whenever you think it's ready. I just run a few quick benchmarks. I don't find any sign of regressions in this branch. My impression from running the same benchmark a few times by hand is that the difference is likely within the trial-to-trial fluctuations. This branch: julia> @btime mul!($(zeros(100, 100)), $(sprandn(100, 100, 0.1)), $(randn(100, 100)));
79.478 μs (0 allocations: 0 bytes)
julia> @btime mul!($(zeros(100, 100)), $(sprandn(100, 100, 0.1)'), $(randn(100, 100)));
73.109 μs (0 allocations: 0 bytes)
julia> @btime $(zeros(100, 100)) .= $(sprandn(100, 100, 0.1)) .* $(randn(100, 100));
56.604 μs (0 allocations: 0 bytes) With julia> @btime mul!($(zeros(100, 100)), $(sprandn(100, 100, 0.1)), $(randn(100, 100)));
83.647 μs (0 allocations: 0 bytes)
julia> @btime mul!($(zeros(100, 100)), $(sprandn(100, 100, 0.1)'), $(randn(100, 100)));
69.138 μs (0 allocations: 0 bytes)
julia> @btime $(zeros(100, 100)) .= $(sprandn(100, 100, 0.1)) .* $(randn(100, 100));
58.008 μs (0 allocations: 0 bytes)
julia> VERSION
v"1.3.0-alpha.154" |
Is it possible to do some Compat stuff to prevent breakage? I think there is rampant use of sparse matrix fields everywhere. Do we want to make this a deprecation in 1.3 and remove direct field access in only 1.4? Technically this wasn't a documented API, so it is not strictly necessary, but it might be nice to have. Also, we should make these accessor methods documented APIs. Should also go into NEWS. Can do in subsequent PRs. |
Actually, I wonder whether we should drop |
Thanks for the very quick review and merge!
I tried to not break anything. Field access is still allowed: julia> A = spzeros(10, 10)
10×10 SparseMatrixCSC{Float64,Int64} with 0 stored entries
julia> A.nzval
0-element Array{Float64,1} If you are referring to
Yes, I think that makes sense. Relate to this, I think it's possible to get rid of the majority of |
Ah - I missed that the |
It looks like the accessor like |
Can you remove |
Maybe we should open up an issue for the deprecation of direct field access before making a PR. It may not be a popular decision. We should still document the accessor API and put the accessors as the preferred way for the NEWS - even if we don't end up deprecating direct field access. |
Got it. Please see #33050. |
This is the first step towards extensible sparse arrays. Based on discussion with @ViralBShah #30173 (comment), I changed all code touching fields of
SparseMatrixCSC
andSparseVector
with the corresponding accessor methods that already exist.I'd like to make this PR minimal and mechanistic to focus on the refactoring side. I prefer to do the second step mentioned in #30173 (comment) later.