Skip to content

Commit

Permalink
Make inv of Adjoint and Transpose inferable and make it work when (Ju…
Browse files Browse the repository at this point in the history
…liaLang#30047)

the wrapped array is complex.

Fixes JuliaLang#30038
  • Loading branch information
andreasnoack committed Nov 16, 2018
1 parent 11243da commit 25d0dfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ function inv(A::AbstractMatrix{T}) where T
dest = Matrix{S0}(I, n, n)
ldiv!(factorize(convert(AbstractMatrix{S}, A)), dest)
end
inv(A::Adjoint) = adjoint(inv(parent(A)))
inv(A::Transpose) = transpose(inv(parent(A)))

pinv(v::AbstractVector{T}, tol::Real = real(zero(T))) where {T<:Real} = _vectorpinv(transpose, v, tol)
pinv(v::AbstractVector{T}, tol::Real = real(zero(T))) where {T<:Complex} = _vectorpinv(adjoint, v, tol)
Expand Down
11 changes: 4 additions & 7 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,13 @@ end
@testset "inverse of Adjoint" begin
A = randn(n, n)

@test inv(A')*A' ≈ I
@test inv(transpose(A))*transpose(A) ≈ I
@test @inferred(inv(A'))*A' ≈ I
@test @inferred(inv(transpose(A)))*transpose(A) ≈ I

B = complex.(A, randn(n, n))
B = B + transpose(B)

# The following two cases fail because ldiv!(F::Adjoint/Transpose{BunchKaufman},b)
# isn't implemented yet
@test_broken inv(B')*B' ≈ I
@test_broken inv(transpose(B))*transpose(B) ≈ I
@test @inferred(inv(B'))*B' ≈ I
@test @inferred(inv(transpose(B)))*transpose(B) ≈ I
end

end # module TestDense

0 comments on commit 25d0dfc

Please sign in to comment.