Skip to content

more performant SparseMatricCSC constructors for structured matrices #32492

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

Merged
merged 1 commit into from
Jul 5, 2019
Merged

more performant SparseMatricCSC constructors for structured matrices #32492

merged 1 commit into from
Jul 5, 2019

Conversation

dkarrasch
Copy link
Member

This is a follow-up on #32466, implementing what was suggested here #10843 (comment). I was experimenting with all kinds of high-level things, like repeat, and collect of ranges etc., but nothing was working as fast with as little allocations as simply filling undefined vectors of appropriate type (especially repeat was really bad!). Some benchmarks are below. The call to sparse corresponds to the current master code (i.e., "before PR"), the calls to SparseMatrixCSC call functions of this PR ("with PR"). For larger sizes the gain can be a factor larger than 10.

julia> using SparseArrays, LinearAlgebra, BenchmarkTools

julia> m = 1000
1000

julia> T =  Tridiagonal(randn(m-1),randn(m),randn(m-1));

julia> @btime sparse($T);
  27.698 μs (25 allocations: 188.83 KiB)

julia> @btime SparseMatrixCSC($T);
  3.931 μs (7 allocations: 55.09 KiB)

julia> T = SymTridiagonal(randn(m),randn(m-1));

julia> @btime sparse($T);
  27.504 μs (25 allocations: 188.83 KiB)

julia> @btime SparseMatrixCSC($T);
  3.880 μs (7 allocations: 55.09 KiB)

julia> B = Bidiagonal(rand(m), rand(m-1), :U);

julia> @btime sparse($B);
  21.705 μs (20 allocations: 134.38 KiB)

julia> @btime SparseMatrixCSC($B);
  2.664 μs (5 allocations: 39.56 KiB)

julia> B = Bidiagonal(rand(m), rand(m-1), :L);

julia> @btime sparse($B);
  21.365 μs (20 allocations: 134.38 KiB)

julia> @btime SparseMatrixCSC($B);
  2.632 μs (5 allocations: 39.56 KiB)

@andreasnoack andreasnoack added the sparse Sparse arrays label Jul 5, 2019
@andreasnoack andreasnoack merged commit 729e87f into JuliaLang:master Jul 5, 2019
@dkarrasch dkarrasch deleted the dk/structsparse branch July 5, 2019 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants