From 150c1adfd6f1a54e6a74393c7bb73af8f772fa30 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 15:35:31 +0530 Subject: [PATCH] Add single-term multiplication for `AbstractQ` on v1.10 and above (#52342) --- stdlib/LinearAlgebra/src/abstractq.jl | 3 +++ stdlib/LinearAlgebra/test/abstractq.jl | 1 + 2 files changed, 4 insertions(+) diff --git a/stdlib/LinearAlgebra/src/abstractq.jl b/stdlib/LinearAlgebra/src/abstractq.jl index 2aa333beef2b2..b0d53320f4aa3 100644 --- a/stdlib/LinearAlgebra/src/abstractq.jl +++ b/stdlib/LinearAlgebra/src/abstractq.jl @@ -157,6 +157,9 @@ qsize_check(Q::AbstractQ, P::AbstractQ) = size(Q, 2) == size(P, 1) || throw(DimensionMismatch("second dimension of A, $(size(Q,2)), must coincide with first dimension of B, $(size(P,1))")) +# mimic the AbstractArray fallback +*(Q::AbstractQ{<:Number}) = Q + (*)(Q::AbstractQ, J::UniformScaling) = Q*J.λ function (*)(Q::AbstractQ, b::Number) T = promote_type(eltype(Q), typeof(b)) diff --git a/stdlib/LinearAlgebra/test/abstractq.jl b/stdlib/LinearAlgebra/test/abstractq.jl index 83a26c6050484..19b872d685668 100644 --- a/stdlib/LinearAlgebra/test/abstractq.jl +++ b/stdlib/LinearAlgebra/test/abstractq.jl @@ -34,6 +34,7 @@ n = 5 T <: Complex && @test_throws ErrorException transpose(Q) @test convert(AbstractQ{complex(T)}, Q) isa MyQ{complex(T)} @test convert(AbstractQ{complex(T)}, Q') isa AdjointQ{<:complex(T),<:MyQ{complex(T)}} + @test *(Q) == Q @test Q*I ≈ Q.Q*I rtol=2eps(real(T)) @test Q'*I ≈ Q.Q'*I rtol=2eps(real(T)) @test I*Q ≈ Q.Q*I rtol=2eps(real(T))