Skip to content

Commit fd9c49c

Browse files
jishnubKristofferC
authored and
KristofferC
committed
Linalg: matprod_dest for Diagonal and adjvec (#53611)
(cherry picked from commit f882c00)
1 parent 21a2602 commit fd9c49c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stdlib/LinearAlgebra/src/LinearAlgebra.jl

+2
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ matprod_dest(A::Diagonal, B::StructuredMatrix, TS) = similar(B, TS)
581581
matprod_dest(A::Diagonal, B::Diagonal, TS) = similar(B, TS)
582582
matprod_dest(A::HermOrSym, B::Diagonal, TS) = similar(A, TS, size(A))
583583
matprod_dest(A::Diagonal, B::HermOrSym, TS) = similar(B, TS, size(B))
584+
# Special handling for adj/trans vec
585+
matprod_dest(A::Diagonal, B::AdjOrTransAbsVec, TS) = similar(B, TS)
584586

585587
# TODO: remove once not used anymore in SparseArrays.jl
586588
# some trait like this would be cool

stdlib/LinearAlgebra/test/diagonal.jl

+11
Original file line numberDiff line numberDiff line change
@@ -1277,4 +1277,15 @@ end
12771277
@test c == Diagonal([2,2,2,2])
12781278
end
12791279

1280+
@testset "mul/div with an adjoint vector" begin
1281+
A = [1.0;;]
1282+
x = [1.0]
1283+
yadj = Diagonal(A) \ x'
1284+
@test typeof(yadj) == typeof(x')
1285+
@test yadj == x'
1286+
yadj = Diagonal(A) * x'
1287+
@test typeof(yadj) == typeof(x')
1288+
@test yadj == x'
1289+
end
1290+
12801291
end # module TestDiagonal

0 commit comments

Comments
 (0)