Skip to content

Commit 64d20d2

Browse files
andreasnoackKristofferC
authored andcommitted
Make pinv work for Adjoint (#29837)
Fixes #29723 (cherry picked from commit a472bc7)
1 parent 10513fd commit 64d20d2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ julia> M * N
12621262
12631263
[^KY88]: Konstantinos Konstantinides and Kung Yao, "Statistical analysis of effective singular values in matrix rank determination", IEEE Transactions on Acoustics, Speech and Signal Processing, 36(5), 1988, 757-763. [doi:10.1109/29.1585](https://doi.org/10.1109/29.1585)
12641264
"""
1265-
function pinv(A::StridedMatrix{T}, rtol::Real) where T
1265+
function pinv(A::AbstractMatrix{T}, rtol::Real) where T
12661266
m, n = size(A)
12671267
Tout = typeof(zero(T)/sqrt(one(T) + one(T)))
12681268
if m == 0 || n == 0
@@ -1291,7 +1291,7 @@ function pinv(A::StridedMatrix{T}, rtol::Real) where T
12911291
Sinv[findall(.!isfinite.(Sinv))] .= zero(Stype)
12921292
return SVD.Vt' * (Diagonal(Sinv) * SVD.U')
12931293
end
1294-
function pinv(A::StridedMatrix{T}) where T
1294+
function pinv(A::AbstractMatrix{T}) where T
12951295
rtol = eps(real(float(one(T))))*min(size(A)...)
12961296
return pinv(A, rtol)
12971297
end

stdlib/LinearAlgebra/test/dense.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ bimg = randn(n,2)/2
8787
pinva15 = pinv(a[:,1:n1])
8888
@test a[:,1:n1]*pinva15*a[:,1:n1] a[:,1:n1]
8989
@test pinva15*a[:,1:n1]*pinva15 pinva15
90+
pinva15 = pinv(a[:,1:n1]') # the Adjoint case
91+
@test a[:,1:n1]'*pinva15*a[:,1:n1]' a[:,1:n1]'
92+
@test pinva15*a[:,1:n1]'*pinva15 pinva15
9093

9194
@test size(pinv(Matrix{eltya}(undef,0,0))) == (0,0)
9295
end

0 commit comments

Comments
 (0)