Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/host/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ function Base.:\(D::Diagonal{<:Any, <:AbstractGPUArray}, B::AbstractGPUVecOrMat)
end
end

function LinearAlgebra.mul!(C::Diagonal{<:Any, <:AbstractGPUArray},
A::Diagonal{<:Any, <:AbstractGPUArray},
B::Diagonal{<:Any, <:AbstractGPUArray})
dc = C.diag
da = A.diag
db = B.diag
d = length(dc)
length(da) == d || throw(DimensionMismatch("right hand side has $(length(da)) rows but output is $d by $d"))
length(db) == d || throw(DimensionMismatch("left hand side has $(length(db)) rows but output is $d by $d"))
@. dc = da * db

return C
end

function LinearAlgebra.mul!(B::AbstractGPUVecOrMat,
D::Diagonal{<:Any, <:AbstractGPUArray},
A::AbstractGPUVecOrMat)
Expand Down
7 changes: 7 additions & 0 deletions test/testsuite/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@
mul!(X, B, D, α, β)
mul!(Y, collect(B), Diagonal(collect(d)), α, β)
@test collect(X) ≈ Y
a = AT(rand(elty, n))
b = AT(rand(elty, n))
C = Diagonal(d)
B = Diagonal(b)
A = Diagonal(a)
mul!(C, A, B)
@test collect(C.diag) ≈ collect(A.diag) .* collect(B.diag)
end
end

Expand Down
Loading