You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Factor `K` into components `K.L`, `K.U`, and `K.F`.
482
493
This function will perform both the symbolic and numeric steps of factoriation on an
483
494
existing `KLUFactorization` instance.
484
495
496
+
# Arguments
497
+
- `K::KLUFactorization`: The matrix factorization object to be factored.
498
+
- `check::Bool`: If `true` (default) check for errors after the factorization. If `false` errors must be checked by the user with `klu.common.status`.
499
+
- `allowsingular::Bool`: If `true` (default `false`) allow the factorization to proceed even if the matrix is singular. Note that this will allow for
500
+
silent divide by zero errors in subsequent `solve!` or `ldiv!` calls if singularity is not checked by the user with `klu.common.status == KLU.KLU_SINGULAR`
501
+
485
502
The `K.common` struct can be used to modify certain options and parameters, see the
@@ -518,6 +535,12 @@ The relation between `K` and `A` is
518
535
519
536
- `LinearAlgebra.\\`
520
537
538
+
# Arguments
539
+
- `A::SparseMatrixCSC` or `n::Integer`, `colptr::Vector{Ti}`, `rowval::Vector{Ti}`, `nzval::Vector{Tv}`: The sparse matrix or the zero-based sparse matrix components to be factored.
540
+
- `check::Bool`: If `true` (default) check for errors after the factorization. If `false` errors must be checked by the user with `klu.common.status`.
541
+
- `allowsingular::Bool`: If `true` (default `false`) allow the factorization to proceed even if the matrix is singular. Note that this will allow for
542
+
silent divide by zero errors in subsequent `solve!` or `ldiv!` calls if singularity is not checked by the user with `klu.common.status == KLU.KLU_SINGULAR`
543
+
521
544
!!! note
522
545
`klu(A::SparseMatrixCSC)` uses the KLU[^ACM907] library that is part of
523
546
SuiteSparse. As this library only supports sparse matrices with [`Float64`](@ref) or
@@ -526,36 +549,68 @@ The relation between `K` and `A` is
526
549
527
550
[^ACM907]: Davis, Timothy A., & Palamadai Natarajan, E. (2010). Algorithm 907: KLU, A Direct Sparse Solver for Circuit Simulation Problems. ACM Trans. Math. Softw., 37(3). doi:10.1145/1824801.1824814
528
551
"""
529
-
functionklu(n, colptr::Vector{Ti}, rowval::Vector{Ti}, nzval::Vector{Tv}) where {Ti<:KLUITypes, Tv<:AbstractFloat}
552
+
functionklu(n, colptr::Vector{Ti}, rowval::Vector{Ti}, nzval::Vector{Tv}; check=true, allowsingular=false) where {Ti<:KLUITypes, Tv<:AbstractFloat}
530
553
if Tv != Float64
531
554
nzval =convert(Vector{Float64}, nzval)
532
555
end
533
556
K =KLUFactorization(n, colptr, rowval, nzval)
534
-
returnklu_factor!(K)
557
+
returnklu_factor!(K; check, allowsingular)
535
558
end
536
559
537
-
functionklu(n, colptr::Vector{Ti}, rowval::Vector{Ti}, nzval::Vector{Tv}) where {Ti<:KLUITypes, Tv<:Complex}
560
+
functionklu(n, colptr::Vector{Ti}, rowval::Vector{Ti}, nzval::Vector{Tv}; check=true, allowsingular=false) where {Ti<:KLUITypes, Tv<:Complex}
538
561
if Tv != ComplexF64
539
562
nzval =convert(Vector{ComplexF64}, nzval)
540
563
end
541
564
K =KLUFactorization(n, colptr, rowval, nzval)
542
-
returnklu_factor!(K)
565
+
returnklu_factor!(K; check, allowsingular)
543
566
end
544
567
545
-
functionklu(A::SparseMatrixCSC{Tv, Ti}) where {Tv<:Union{AbstractFloat, Complex}, Ti<:KLUITypes}
568
+
functionklu(A::SparseMatrixCSC{Tv, Ti}; check=true, allowsingular=false) where {Tv<:Union{AbstractFloat, Complex}, Ti<:KLUITypes}
Recompute the KLU factorization `K` using the values of `A` or `nzval`. The pattern of the original
579
+
matrix used to create `K` must match the pattern of `A`.
580
+
581
+
For sparse `A` with real or complex element type, the return type of `K` is
582
+
`KLUFactorization{Tv, Ti}`, with `Tv` = `Float64` or `ComplexF64`
583
+
respectively and `Ti` is an integer type (`Int32` or `Int64`).
584
+
585
+
See also: [`klu`](@ref)
586
+
587
+
# Arguments
588
+
- `K::KLUFactorization`: The matrix factorization object, previously created by a call to `klu`, to be re-factored.
589
+
- `A::SparseMatrixCSC` or `n::Integer`, `colptr::Vector{Ti}`, `rowval::Vector{Ti}`, `nzval::Vector{Tv}`: The sparse matrix or the zero-based sparse matrix components to be factored.
590
+
- `check::Bool`: If `true` (default) check for errors after the factorization. If `false` errors must be checked by the user with `klu.common.status`.
591
+
- `allowsingular::Bool`: If `true` (default `false`) allow the factorization to proceed even if the matrix is singular. Note that this will allow for
592
+
silent divide by zero errors in subsequent `solve!` or `ldiv!` calls if singularity is not checked by the user with `klu.common.status == KLU.KLU_SINGULAR`
593
+
594
+
!!! note
595
+
`klu(A::SparseMatrixCSC)` uses the KLU[^ACM907] library that is part of
596
+
SuiteSparse. As this library only supports sparse matrices with [`Float64`](@ref) or
597
+
`ComplexF64` elements, `lu` converts `A` into a copy that is of type
598
+
`SparseMatrixCSC{Float64}` or `SparseMatrixCSC{ComplexF64}` as appropriate.
599
+
600
+
[^ACM907]: Davis, Timothy A., & Palamadai Natarajan, E. (2010). Algorithm 907: KLU, A Direct Sparse Solver for Circuit Simulation Problems. ACM Trans. Math. Softw., 37(3). doi:10.1145/1824801.1824814
functionklu!(K::KLUFactorization{U}, S::SparseMatrixCSC{U}) where {U}
630
+
functionklu!(K::KLUFactorization{U}, S::SparseMatrixCSC{U}; check=true, allowsingular=false) where {U}
576
631
size(K) ==size(S) ||throw(ArgumentError("Sizes of K and S must match."))
577
632
increment!(K.colptr)
578
633
increment!(K.rowval)
634
+
# what should happen here when check = false? This is not really a KLU error code.
579
635
K.colptr == S.colptr && K.rowval == S.rowval ||
580
636
(decrement!(K.colptr); decrement!(K.rowval);
581
637
throw(ArgumentError("The pattern of the original matrix must match the pattern of the refactor."))
582
638
)
583
639
decrement!(K.colptr)
584
640
decrement!(K.rowval)
585
-
returnklu!(K, S.nzval)
641
+
returnklu!(K, S.nzval; check, allowsingular)
586
642
end
587
643
588
-
589
644
#B is the modified argument here. To match with the math it should be (klu, B). But convention is
590
645
# modified first. Thoughts?
646
+
647
+
# with check=false it *is technically* possible to enter a seriously invalid state wherein `klu.common`
648
+
# is undefined. I don't think this is possible in practice though, since we throw on invalid `common` on construction.
649
+
"""
650
+
solve!(klu::Union{KLUFactorization, AdjointFact{Tv, KLUFactorization}, TransposeFact{Tv, KLUFactorization}}, B::StridedVecOrMat) -> B
651
+
652
+
Solve the linear system `AX = B` or `A'X = B` where using the matrix facotrization `klu` and right-hand side `B`.
653
+
654
+
This function overwrites `B` with the solution `X`, for a new solution vector `X` use `solve(klu, B)`.
655
+
656
+
# Arguments
657
+
- `klu::KLUFactorization`: The matrix factorization of `A` to use in the solution.
658
+
- `B::StridedVecOrMat`: The right-hand side of the linear system.
659
+
- `check::Bool`: If `true` (default) check for errors after the solve. If `false` errors must be checked using `klu.common.status`. The return value of this function is always `B`, so the status of the solve *must* be checked using the factorization object itself when `check=false`.
660
+
661
+
!!! warning "Solve with a singular factorization object"
662
+
If the factorization object `klu` has `klu.common.status == KLU.KLU_SINGULAR` then the `solve!` or `ldiv!` will result in a silent divide by zero error.
663
+
664
+
This status should be checked by the user before solve calls if singularity checks were disabled on factorization using `check=false` or `allowsingular=true`.
0 commit comments