Skip to content

Commit 70c7ddc

Browse files
authored
Merge pull request #34 from timholy/teh/perf
Improve perf of adjoint multiplication
2 parents bf31fb7 + 13dd74c commit 70c7ddc

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/SparseMatrixCSR.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ end
351351

352352
*(A::SparseMatrixCSR, v::Vector) = (y = similar(v,size(A,1));mul!(y,A,v))
353353

354+
function mul!(y::AbstractVector,A::Adjoint{T, <:SparseMatrixCSR},v::AbstractVector) where T
355+
P = A.parent
356+
P.n == size(y, 1) || throw(DimensionMismatch())
357+
P.m == size(v, 1) || throw(DimensionMismatch())
358+
fill!(y,zero(eltype(y)))
359+
o = getoffset(P)
360+
for row = 1:size(P, 1)
361+
for nz in nzrange(P,row)
362+
col = P.colval[nz]+o
363+
y[col] += P.nzval[nz]*v[row]
364+
end
365+
end
366+
return y
367+
end
368+
369+
*(A::Adjoint{T, <:SparseMatrixCSR}, v::AbstractVector) where T = (y = similar(v, promote_type(eltype(v),T), size(A,1)); mul!(y, A, v))
370+
354371
function show(io::IO, ::MIME"text/plain", S::SparseMatrixCSR)
355372
xnnz = nnz(S)
356373
print(io, S.m, "×", S.n, " ", typeof(S), " with ", xnnz, " stored ",

test/SparseMatrixCSR.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function test_csr(Bi,Tv,Ti)
106106
mul!(z,CSC,x)
107107
@test y z
108108
@test CSR*x CSC*x
109+
@test CSR'*y CSC'*z
109110

110111
mul!(y,CSR,x,1,2)
111112
mul!(z,CSC,x,1,2)

0 commit comments

Comments
 (0)