Skip to content

Commit

Permalink
Linalg: matprod_dest for Diagonal and adjvec (#53611)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 11, 2024
1 parent 2978a64 commit f882c00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ matprod_dest(A::Diagonal, B::StructuredMatrix, TS) = similar(B, TS)
matprod_dest(A::Diagonal, B::Diagonal, TS) = similar(B, TS)
matprod_dest(A::HermOrSym, B::Diagonal, TS) = similar(A, TS, size(A))
matprod_dest(A::Diagonal, B::HermOrSym, TS) = similar(B, TS, size(B))
# Special handling for adj/trans vec
matprod_dest(A::Diagonal, B::AdjOrTransAbsVec, TS) = similar(B, TS)

# TODO: remove once not used anymore in SparseArrays.jl
# some trait like this would be cool
Expand Down
11 changes: 11 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1277,4 +1277,15 @@ end
@test c == Diagonal([2,2,2,2])
end

@testset "mul/div with an adjoint vector" begin
A = [1.0;;]
x = [1.0]
yadj = Diagonal(A) \ x'
@test typeof(yadj) == typeof(x')
@test yadj == x'
yadj = Diagonal(A) * x'
@test typeof(yadj) == typeof(x')
@test yadj == x'
end

end # module TestDiagonal

0 comments on commit f882c00

Please sign in to comment.