Skip to content

Commit 3e34cbb

Browse files
jmertdkarrasch
authored andcommitted
Support Factorization \ UniformScaling (#33994)
1 parent 630a551 commit 3e34cbb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

stdlib/LinearAlgebra/src/uniformscaling.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ end
210210
rmul!(inv(A), J.λ)
211211
\(J::UniformScaling, A::AbstractVecOrMat) = J.λ == 0 ? throw(SingularException(1)) : J.λ\A
212212
\(A::AbstractMatrix, J::UniformScaling) = rmul!(inv(A), J.λ)
213+
\(F::Factorization, J::UniformScaling) = F \ J(size(F,1))
213214

214215
\(x::Number, J::UniformScaling) = UniformScaling(x\J.λ)
215216

stdlib/LinearAlgebra/test/uniformscaling.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,37 @@ end
354354
@test dot([x], λ*I, [y]) dot(x, λ, y) dot(x, λ*y)
355355
end
356356

357+
@testset "Factorization solutions" begin
358+
J = complex(randn(),randn()) * I
359+
qrp = A -> qr(A, Val(true))
360+
361+
# thin matrices
362+
X = randn(3,2)
363+
Z = pinv(X)
364+
for fac in (qr,qrp,svd)
365+
F = fac(X)
366+
@test @inferred(F \ I) Z
367+
@test @inferred(F \ J) Z * J
368+
end
369+
370+
# square matrices
371+
X = randn(3,3)
372+
X = X'X + rand()I # make positive definite for cholesky
373+
Z = pinv(X)
374+
for fac in (bunchkaufman,cholesky,lu,qr,qrp,svd)
375+
F = fac(X)
376+
@test @inferred(F \ I) Z
377+
@test @inferred(F \ J) Z * J
378+
end
379+
380+
# fat matrices - only rank-revealing variants
381+
X = randn(2,3)
382+
Z = pinv(X)
383+
for fac in (qrp,svd)
384+
F = fac(X)
385+
@test @inferred(F \ I) Z
386+
@test @inferred(F \ J) Z * J
387+
end
388+
end
389+
357390
end # module TestUniformscaling

0 commit comments

Comments
 (0)