JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.74k stars 5.48k forks source link

inv(transpose(X)) missing a method? #28782

Closed mortenpi closed 5 years ago

mortenpi commented 6 years ago

On 0.7/1.0 I am seeing the following issue:

julia> X = [0.707107 0.707107 0.0; 0.707107 -0.707107 0.0; 0.0 0.0 1.0];

julia> inv(Array(transpose(X))) # Works

julia> inv(transpose(X))
ERROR: LoadError: MethodError: no method matching transpose(::LinearAlgebra.LDLt{Float64,LinearAlgebra.SymTridiagonal{Float64,Array{Float64,1}}})

It should probably be possible to just invert this type of matrix.

andreasnoack commented 6 years ago

I agree that we should support this operation. We probably need to enable general testing of Transpose and Adjoint in the test suite (which unfortunately will make the linear algebra tests even slower.)

kragol commented 6 years ago

This is not the first case of missing methods with Adjoint/Transpose types in the LinearAlgebra package (see e.g. issues #28714 and #27132, the latter being fixed in PR #27916).

As for tests to add, there seems to be quite a few. A quick grep indicates that the following LinearAlgebra test files do not even contain the word transpose

cholesky.jl
eigen.jl
hessenberg.jl
pinv.jl
special.jl
structuredbroadcast.jl
trickyarithmetic.jl

(They might not include tests for adjoints either but grep is less helpful there.)

Could there be a way to automatically add tests for Adjoint/Transpose types whenever a test involves a matrix? Using some kind of modified @test macro perhaps?

garrison commented 6 years ago

From Discourse: inv(transpose(reshape([3.0], 1, 1))) also fails, but with ERROR: MethodError: no method matching ldiv!(::Float64, ::Array{Float64,2}).

goggle commented 5 years ago

This issue seems to be solved, right?

On Julia 1.1.1:

X = [0.707107 0.707107 0.0; 0.707107 -0.707107 0.0; 0.0 0.0 1.0];
inv(transpose(X))

Result:

3×3 LinearAlgebra.Transpose{Float64,Array{Float64,2}}:
  0.707107   0.707107  0.0
  0.707107  -0.707107  0.0
 -0.0       -0.0       1.0