Skip to content

Commit

Permalink
Fix sparse mul!
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Apr 26, 2020
1 parent 92082a5 commit f380ccd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sparse/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Base.:(\)(adjA::Adjoint{T, LowerTriangular{T, S}},B::CuMatrix{T}) where {T<:Blas

LinearAlgebra.mul!(C::CuVector{T},A::CuSparseMatrix,B::CuVector) where {T} = mv!('N',one(T),A,B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},transA::Transpose{<:Any,<:CuSparseMatrix},B::CuVector) where {T} = mv!('T',one(T),parent(transA),B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},adjA::Adjoint{<:Any,<:CuSparseMatrix},B::CuVector) where {T} = mv!('C',one(T),parent(transA),B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},adjA::Adjoint{<:Any,<:CuSparseMatrix},B::CuVector) where {T} = mv!('C',one(T),parent(adjA),B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},A::HermOrSym{T,<:CuSparseMatrix{T}},B::CuVector{T}) where T = mv!('N',one(T),A,B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},transA::Transpose{<:Any, <:HermOrSym{T,<:CuSparseMatrix{T}}},B::CuVector{T}) where {T} = mv!('T',one(T),parent(transA),B,zero(T),C,'O')
LinearAlgebra.mul!(C::CuVector{T},adjA::Adjoint{<:Any, <:HermOrSym{T,<:CuSparseMatrix{T}}},B::CuVector{T}) where {T} = mv!('C',one(T),parent(adjA),B,zero(T),C,'O')
Expand Down
46 changes: 46 additions & 0 deletions test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2006,4 +2006,50 @@ end
end
end

@testset "mul!" begin
for elty in [Float32,Float64,ComplexF32,ComplexF64]
A = sparse(rand(elty,m,m))
x = rand(elty,m)
y = rand(elty,m)
@testset "csr" begin
d_x = CuArray(x)
d_y = CuArray(y)
d_A = CuSparseMatrixCSR(A)
d_Aᵀ = transpose(d_A)
d_Aᴴ = adjoint(d_A)
CUSPARSE.mul!(d_y, d_A, d_x)
h_y = collect(d_y)
z = A * x
@test z h_y
CUSPARSE.mul!(d_y, d_Aᵀ, d_x)
h_y = collect(d_y)
z = transpose(A) * x
@test z h_y
CUSPARSE.mul!(d_y, d_Aᴴ, d_x)
h_y = collect(d_y)
z = adjoint(A) * x
@test z h_y
end
@testset "csc" begin
d_x = CuArray(x)
d_y = CuArray(y)
d_A = CuSparseMatrixCSC(A)
d_Aᵀ = transpose(d_A)
d_Aᴴ = adjoint(d_A)
CUSPARSE.mul!(d_y, d_A, d_x)
h_y = collect(d_y)
z = A * x
@test z h_y
CUSPARSE.mul!(d_y, d_Aᵀ, d_x)
h_y = collect(d_y)
z = transpose(A) * x
@test z h_y
CUSPARSE.mul!(d_y, d_Aᴴ, d_x)
h_y = collect(d_y)
z = adjoint(A) * x
@test z h_y
end
end
end

end

0 comments on commit f380ccd

Please sign in to comment.