Skip to content

Commit de0eef5

Browse files
add the other linear solving instances
1 parent ba77e1e commit de0eef5

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

docs/src/linearalgebra.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ running the full factorization. This thus allows for building types to hold the
2929
without having to perform expensive extra computations.
3030

3131
```@docs
32+
ArrayInterface.bunchkaufman_instance
33+
ArrayInterface.cholesky_instance
34+
ArrayInterface.ldlt_instance
3235
ArrayInterface.lu_instance
3336
ArrayInterface.qr_instance
3437
ArrayInterface.svd_instance

src/ArrayInterface.jl

Lines changed: 63 additions & 4 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+
bunchkaufman_instance(A, pivot = LinearAlgebra.RowMaximum()) -> bunchkaufman_factorization_instance
445+
446+
Returns an instance of the Cholesky factorization object with the correct type
447+
cheaply.
448+
"""
449+
function bunchkaufman_instance(A::Matrix{T}) where T
450+
return bunchkaufman(similar(A, 0, 0), check = false)
451+
end
452+
function bunchkaufman_instance(A::SparseMatrixCSC)
453+
bunchkaufman(sparse(similar(A, 1, 1)), check = false)
454+
end
455+
456+
"""
457+
bunchkaufman_instance(a::Number) -> a
458+
459+
Returns the number.
460+
"""
461+
bunchkaufman_instance(a::Number) = a
462+
463+
"""
464+
bunchkaufman_instance(a::Any) -> cholesky(a, check=false)
465+
466+
Returns the number.
467+
"""
468+
bunchkaufman_instance(a::Any) = bunchkaufman(a, check = false)
469+
443470
"""
444471
cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorization_instance
445472
@@ -463,10 +490,39 @@ cholesky_instance(a::Number, pivot = LinearAlgebra.RowMaximum()) = a
463490
"""
464491
cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) -> cholesky(a, check=false)
465492
466-
Returns the number.
493+
Slow fallback which gets the instance via factorization. Should get
494+
specialized for new matrix types.
467495
"""
468496
cholesky_instance(a::Any, pivot = LinearAlgebra.RowMaximum()) = cholesky(a, pivot, check = false)
469497

498+
"""
499+
ldlt_instance(A) -> ldlt_factorization_instance
500+
501+
Returns an instance of the LDLT factorization object with the correct type
502+
cheaply.
503+
"""
504+
function ldlt_instance(A::Matrix{T}) where {T}
505+
return ldlt(SymTridiagonal(similar(A, 0, 0)), check = false)
506+
end
507+
function ldlt_instance(A::SparseMatrixCSC)
508+
ldlt(sparse(similar(A, 1, 1)), check = false)
509+
end
510+
511+
"""
512+
ldlt_instance(a::Number) -> a
513+
514+
Returns the number.
515+
"""
516+
ldlt_instance(a::Number) = a
517+
518+
"""
519+
ldlt_instance(a::Any) -> ldlt(a, check=false)
520+
521+
Slow fallback which gets the instance via factorization. Should get
522+
specialized for new matrix types.
523+
"""
524+
ldlt_instance(a::Any) = ldlt(a)
525+
470526
"""
471527
lu_instance(A) -> lu_factorization_instance
472528
@@ -505,7 +561,8 @@ lu_instance(a::Number) = a
505561
"""
506562
lu_instance(a::Any) -> lu(a, check=false)
507563
508-
Returns the number.
564+
Slow fallback which gets the instance via factorization. Should get
565+
specialized for new matrix types.
509566
"""
510567
lu_instance(a::Any) = lu(a, check = false)
511568

@@ -534,7 +591,8 @@ qr_instance(a::Number) = a
534591
"""
535592
qr_instance(a::Any) -> qr(a)
536593
537-
Returns the number.
594+
Slow fallback which gets the instance via factorization. Should get
595+
specialized for new matrix types.
538596
"""
539597
qr_instance(a::Any) = qr(a)# check = false)
540598

@@ -558,7 +616,8 @@ svd_instance(a::Number) = a
558616
"""
559617
svd_instance(a::Any) -> svd(a)
560618
561-
Returns the number.
619+
Slow fallback which gets the instance via factorization. Should get
620+
specialized for new matrix types.
562621
"""
563622
svd_instance(a::Any) = svd(a) #check = false)
564623

0 commit comments

Comments
 (0)