Pinv of matrix transpose?

I tried to use pinv on a transposed matrix and it surprisingly err’d out. What is the correct way to go about this?

julia> using LinearAlgebra

julia> A = rand(3,2)
3×2 Array{Float64,2}:
0.384492  0.512766
0.894825  0.866387
0.821847  0.945962

julia> pinv(A)
2×3 Array{Float64,2}:
-4.39446   5.15053  -2.33521
 4.29807  -4.26865   2.63689

julia> pinv(A')
ERROR: MethodError: no method matching pinv(::Adjoint{Float64,Array{Float64,2}})

julia> pinv(transpose(A))
ERROR: MethodError: no method matching pinv(::Transpose{Float64,Array{Float64,2}})

What version of Julia are you using? I can’t reproduce with 1.1.0.

Anyway you can convert a Adjoint or Transpose matrix type to a regular Array using collect.
So try

julia> pinv(collect(A'))

(maybe there’s something else wrong, there should be pinv for Transpose’d arrays)

1 Like

Thanks! I am on julia 1.0.1. I’ll try upgrading and see whether that fixes it.
Collecting works in the mean time too!

You should use copy instead of collect for materializing lazy adjoints/transposes.

1 Like

It was fixed in

Julia 1.1.0 did fix my issue!

1 Like