Skip to content

Cholesky factorization of a Tridiagonal matrix should not be dense #1383

@ranocha

Description

@ranocha

The Cholesky factorization $A = G G^T$ of a banded matrix $A$ preserves the lower bandwidth, i.e., $G$ has the same lower bandwidth as $A$. In particular, the Cholesky factorization of a Tridiagonal matrix should be Bidiagonal. However, (at least) Julia 1.10 uses a dense matrix:

julia> using LinearAlgebra

julia> A = Tridiagonal(ones(4), 2 * ones(5), ones(4))
5×5 Tridiagonal{Float64, Vector{Float64}}:
 2.0  1.0            
 1.0  2.0  1.0        
     1.0  2.0  1.0    
         1.0  2.0  1.0
             1.0  2.0

julia> cholesky(A)
Cholesky{Float64, Matrix{Float64}}
U factor:
5×5 UpperTriangular{Float64, Matrix{Float64}}:
 1.41421  0.707107  0.0       0.0       0.0
         1.22474   0.816497  0.0       0.0
                  1.1547    0.866025  0.0
                           1.11803   0.894427
                                    1.09545

julia> LinearAlgebra.cholcopy(A)
5×5 Matrix{Float64}:
 2.0  1.0  0.0  0.0  0.0
 1.0  2.0  1.0  0.0  0.0
 0.0  1.0  2.0  1.0  0.0
 0.0  0.0  1.0  2.0  1.0
 0.0  0.0  0.0  1.0  2.0

The issue seems to be mostly related to cholcopy, since the in-place factorization looks better (but I did not benchmark it in detail):

julia> cholesky!(A)
Cholesky{Float64, Tridiagonal{Float64, Vector{Float64}}}
U factor:
5×5 UpperTriangular{Float64, Tridiagonal{Float64, Vector{Float64}}}:
 1.41421  0.707107  0.0       0.0       0.0
         1.22474   0.816497  0.0       0.0
                  1.1547    0.866025  0.0
                           1.11803   0.894427
                                    1.09545

I consider this to be a performance bug since this makes the cholesky decomposition of a Tridiagonal matrix as slow as that of a dense matrix.

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