Skip to content

Issues with inv(Triangular) #239

@DanielVandH

Description

@DanielVandH

Consider

julia> using LazyArrays, ArrayLayouts, LinearAlgebra

julia> A = UpperTriangular(ApplyArray(inv, rand(5, 5)))
5×5 UpperTriangular{Float64, ApplyArray{Float64, 2, typeof(inv), Tuple{Matrix{Float64}}}}:
 2.35135   1.68449   -1.84848   -0.955078  -1.85021
         -0.271777  -1.25844    0.94071   -1.27413
                   -0.124992  -1.4524     2.35783
                              0.669905  -0.609163
                                        0.840739

julia> inv(A)
inv(5×5 UpperTriangular{Float64, ApplyArray{Float64, 2, typeof(inv), Tuple{Matrix{Float64}}}}):
  0.425287   2.63595  -32.8287   -74.2701    43.1852
 -0.0       -3.67949   37.0457    85.4846   -47.5317
 -0.0       -0.0       -8.00051  -17.3457     9.86934
  0.0        0.0        0.0        1.49275    1.08158
  0.0        0.0        0.0        0.0        1.18943

julia> MemoryLayout(inv(A))
LazyArrays.InvLayout{TriangularLayout{'U', 'N', LazyArrays.LazyLayout}}()

The LazyArrays.InvLayout{TriangularLayout{'U', 'N', LazyArrays.LazyLayout}}() could maybe be TriangularLayout{'L', 'N', LazyArrays.LazyLayout}()? (Actually doing

applylayout(::Type{typeof(inv)}, ::TriangularLayout{'U', UNIT, ML}) where {UNIT, ML} = TriangularLayout{'L', UNIT, ML}()
applylayout(::Type{typeof(inv)}, ::TriangularLayout{'L', UNIT, ML}) where {UNIT, ML} = TriangularLayout{'U', UNIT, ML}()

causes more issues with stackoverflows, so I guess the Inv should stay in the layout.) One issue that the current situation causes is e.g.

julia> using BandedMatrices

julia> colsupport(inv(A), 1)
Base.OneTo(5)

which is of course more problematic for infinite matrices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions