Skip to content

Review of matprod_dest behaviour with sparse factors#693

Open
dkarrasch wants to merge 8 commits intomainfrom
dk/cleanup-matprod_dest
Open

Review of matprod_dest behaviour with sparse factors#693
dkarrasch wants to merge 8 commits intomainfrom
dk/cleanup-matprod_dest

Conversation

@dkarrasch
Copy link
Copy Markdown
Member

This intends to fix the unexpected matrix return type behaviour observed in #685 (comment). The goal is determine the return type by the (potentially) non-sparse factor. For BandedMatrix types, however, the return type should be sparse, since these are themselves "sparse".

I can't seem to be able to run tests, but it seems that this yields a major speed-up in multiplication, and so fixes #685 (to be confirmed).

@dkarrasch
Copy link
Copy Markdown
Member Author

This obviously changes return types and is therefore not for backport (except for v1.13?).

@dkarrasch
Copy link
Copy Markdown
Member Author

With this PR, I get (after pre-compilation)

julia> using LinearAlgebra, SparseArrays

julia> A = Hermitian(sprand(5000, 5000, .01));

julia> X = rand(5000, 10);

julia> Y = rand(10, 5000);

julia> @time A * X;
  0.002859 seconds (6 allocations: 390.789 KiB)

julia> @time Y * A;
  0.001683 seconds (3 allocations: 390.711 KiB)

julia> @time A * Y';
  2.896842 seconds (4 allocations: 390.727 KiB)

julia> @time X' * A;
  0.001743 seconds (4 allocations: 390.727 KiB)

The case A*Y is fixed by #692. With that fix applied, I get (after pre-compilation)

julia> using LinearAlgebra, SparseArrays

julia> A = Hermitian(sprand(5000, 5000, .01));

julia> X = rand(5000, 10);

julia> Y = rand(10, 5000);

julia> @time A * X;
  0.002663 seconds (6 allocations: 390.789 KiB)

julia> @time Y * A;
  0.001571 seconds (3 allocations: 390.711 KiB)

julia> @time A * Y';
  0.002957 seconds (8 allocations: 390.820 KiB)

julia> @time X' * A;
  0.001666 seconds (4 allocations: 390.727 KiB)

@dkarrasch
Copy link
Copy Markdown
Member Author

I wonder if we really need the StructuredMatrix methods over at LinearAlgebra.jl. They require massive disambiguation here, but since the fallback is to call 3-arg similar, I don't think they add anything that the fallback wouldn't give already. @jishnub

@dkarrasch
Copy link
Copy Markdown
Member Author

After JuliaLang/LinearAlgebra.jl#1572, the current state of this PR should be enough to create dense target arrays as long as one factor is dense and the other is "quasi-sparse", meaning sparse or a wrapper of a sparse array. Sparse times banded would yield sparse arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extremely slow matrix multiplication with Hermitian{T, SparseMatrixCSC{T, I}} and Symmetric{T, SparseMatrixCSC{T, I}}.

1 participant