From a5a98984ebb97afed547fd79eeb350f8182ef15d Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 6 Mar 2024 00:40:15 +0530 Subject: [PATCH] Linalg: matprod_dest for Diagonal and adjvec --- stdlib/LinearAlgebra/src/LinearAlgebra.jl | 2 ++ stdlib/LinearAlgebra/test/diagonal.jl | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 9b9aaf0d9581d..a8c6792178aec 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -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 diff --git a/stdlib/LinearAlgebra/test/diagonal.jl b/stdlib/LinearAlgebra/test/diagonal.jl index 18abc6940eded..3087e87f63415 100644 --- a/stdlib/LinearAlgebra/test/diagonal.jl +++ b/stdlib/LinearAlgebra/test/diagonal.jl @@ -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