Skip to content

Commit ba77e1e

Browse files
Add Cholesky Instance
1 parent cc35f7b commit ba77e1e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/ArrayInterface.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,33 @@ matrix_colors(A::Bidiagonal) = _cycle(1:2, Base.size(A, 2))
440440
matrix_colors(A::Union{Tridiagonal, SymTridiagonal}) = _cycle(1:3, Base.size(A, 2))
441441
_cycle(repetend, len) = repeat(repetend, div(len, length(repetend)) + 1)[1:len]
442442

443+
"""
444+
cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorization_instance
445+
446+
Returns an instance of the Cholesky factorization object with the correct type
447+
cheaply.
448+
"""
449+
function cholesky_instance(A::Matrix{T}, pivot = LinearAlgebra.RowMaximum()) where {T}
450+
return cholesky(similar(A, 0, 0), pivot, check = false)
451+
end
452+
function cholesky_instance(A::SparseMatrixCSC)
453+
cholesky(sparse(similar(A, 1, 1)), check = false)
454+
end
455+
456+
"""
457+
cholesky_instance(a::Number, pivot = LinearAlgebra.RowMaximum()) -> a
458+
459+
Returns the number.
460+
"""
461+
cholesky_instance(a::Number, pivot = LinearAlgebra.RowMaximum()) = a
462+
463+
"""
464+
cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)
465+
466+
Returns the number.
467+
"""
468+
cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) = cholesky(a, pivot, check = false)
469+
443470
"""
444471
lu_instance(A) -> lu_factorization_instance
445472

0 commit comments

Comments
 (0)