Skip to content

Commit 13dd74c

Browse files
committed
Improve perf of adjoint multiplication
1 parent 5e629bd commit 13dd74c

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
@@ -346,6 +346,23 @@ end
346346

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

349+
function mul!(y::AbstractVector,A::Adjoint{T, <:SparseMatrixCSR},v::AbstractVector) where T
350+
P = A.parent
351+
P.n == size(y, 1) || throw(DimensionMismatch())
352+
P.m == size(v, 1) || throw(DimensionMismatch())
353+
fill!(y,zero(eltype(y)))
354+
o = getoffset(P)
355+
for row = 1:size(P, 1)
356+
for nz in nzrange(P,row)
357+
col = P.colval[nz]+o
358+
y[col] += P.nzval[nz]*v[row]
359+
end
360+
end
361+
return y
362+
end
363+
364+
*(A::Adjoint{T, <:SparseMatrixCSR}, v::AbstractVector) where T = (y = similar(v, promote_type(eltype(v),T), size(A,1)); mul!(y, A, v))
365+
349366
function show(io::IO, ::MIME"text/plain", S::SparseMatrixCSR)
350367
xnnz = nnz(S)
351368
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)