SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

dot with Symmetric view of sparse matrix is very slow

Open goulart-paul opened this issue 3 years ago • 1 comments

Calling three argument dot with a Symmetric view of a sparse matrix is very slow.

Example:

A = sprandn(1000,1000,0.1)
A = A+A'   #symmetric 
B = Symmetric(triu(A))

The quadratic form x'*B*x is about 100x slower using dot, although fine when computed directly. The same operation is about the same either way using A.

julia> @btime ($x'*$A*$x);
  173.777 μs (1 allocation: 7.94 KiB)

julia> @btime ($x'*$B*$x);
  97.280 μs (1 allocation: 7.94 KiB)

julia> @btime dot($x,$A,$x);
  174.176 μs (0 allocations: 0 bytes)

julia> @btime dot($x,$B,$x);
  9.559 ms (0 allocations: 0 bytes)

The final case above ends up appears to be falling back on the general symmetric dot implementation here.

This might be related to #23.

goulart-paul avatar Feb 22 '22 20:02 goulart-paul

Perhaps just need to use parent or something.

ViralBShah avatar Mar 09 '22 14:03 ViralBShah