Skip to content

Commit 3f62e1b

Browse files
format
1 parent 536611a commit 3f62e1b

File tree

11 files changed

+761
-224
lines changed

11 files changed

+761
-224
lines changed

benchmarks/applelu.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ for i in 1:length(ns)
3939
for j in 1:length(algs)
4040
bt = @belapsed solve(prob, $(algs[j])).u setup=(prob = LinearProblem(copy(A),
4141
copy(b);
42-
u0 = copy(u0),
42+
u0 = copy(u0),
4343
alias = LinearAliasSpecifier(alias_A = true, alias_b = true)
44-
))
44+
))
4545
push!(res[j], luflop(n) / bt / 1e9)
4646
end
4747
end

docs/src/advanced/developing.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ basic machinery. A simplified version is:
1717
```julia
1818
struct MyLUFactorization{P} <: LinearSolve.SciMLLinearSolveAlgorithm end
1919

20-
function LinearSolve.init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol, reltol,
20+
function LinearSolve.init_cacheval(
21+
alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol, reltol,
2122
verbose::Bool, assump::LinearSolve.OperatorAssumptions)
2223
lu!(convert(AbstractMatrix, A))
2324
end
@@ -41,7 +42,8 @@ need to cache their own things, and so there's one value `cacheval` that is
4142
for the algorithms to modify. The function:
4243

4344
```julia
44-
init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose, assump)
45+
init_cacheval(
46+
alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose, assump)
4547
```
4648

4749
is what is called at `init` time to create the first `cacheval`. Note that this

docs/src/basics/common_solver_opts.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ in order to give composability. These are also the options taken at `init` time.
66
The following are the options these algorithms take, along with their defaults.
77

88
## General Controls
9+
910
- `alias::LinearAliasSpecifier`: Holds the fields `alias_A` and `alias_b` which specify
1011
whether to alias the matrices `A` and `b` respectively. When these fields are `true`,
1112
`A` and `b` can be written to and changed by the solver algorithm. When fields are `nothing`
12-
the default behavior is used, which is to default to `true` when the algorithm is known
13+
the default behavior is used, which is to default to `true` when the algorithm is known
1314
not to modify the matrices, and false otherwise.
1415
- `verbose`: Whether to print extra information. Defaults to `false`.
1516
- `assumptions`: Sets the assumptions of the operator in order to effect the default

ext/LinearSolveSparseArraysExt.jl

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ include("../src/KLU/klu.jl")
1212

1313
LinearSolve.issparsematrixcsc(A::AbstractSparseMatrixCSC) = true
1414
LinearSolve.issparsematrix(A::AbstractSparseArray) = true
15-
LinearSolve.make_SparseMatrixCSC(A::AbstractSparseArray) = SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))
16-
LinearSolve.makeempty_SparaseMatrixCSC(A::AbstractSparseArray) = SparseMatrixCSC(0, 0, [1], Int[], eltype(A)[])
15+
function LinearSolve.make_SparseMatrixCSC(A::AbstractSparseArray)
16+
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))
17+
end
18+
function LinearSolve.makeempty_SparaseMatrixCSC(A::AbstractSparseArray)
19+
SparseMatrixCSC(0, 0, [1], Int[], eltype(A)[])
20+
end
1721

1822
function LinearSolve.init_cacheval(alg::RFLUFactorization,
1923
A::Union{AbstractSparseArray, LinearSolve.SciMLOperators.AbstractSciMLOperator}, b, u, Pl, Pr,
@@ -22,7 +26,6 @@ function LinearSolve.init_cacheval(alg::RFLUFactorization,
2226
nothing, nothing
2327
end
2428

25-
2629
function LinearSolve.init_cacheval(
2730
alg::QRFactorization, A::Symmetric{<:Number, <:SparseMatrixCSC}, b, u, Pl, Pr,
2831
maxiters::Int, abstol, reltol, verbose::Bool,
@@ -32,12 +35,12 @@ end
3235

3336
function LinearSolve.handle_sparsematrixcsc_lu(A::AbstractSparseMatrixCSC)
3437
lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)),
35-
check = false)
38+
check = false)
3639
end
3740

3841
function LinearSolve.defaultalg(
3942
A::Symmetric{<:Number, <:SparseMatrixCSC}, b, ::OperatorAssumptions{Bool})
40-
LinearSolve.DefaultLinearSolver(LinearSolve.DefaultAlgorithmChoice.CHOLMODFactorization)
43+
LinearSolve.DefaultLinearSolver(LinearSolve.DefaultAlgorithmChoice.CHOLMODFactorization)
4144
end
4245

4346
function LinearSolve.defaultalg(A::AbstractSparseMatrixCSC{Tv, Ti}, b,
@@ -61,14 +64,16 @@ end
6164
const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1],
6265
Int[], Float64[]))
6366

64-
function LinearSolve.init_cacheval(alg::UMFPACKFactorization, A::SparseMatrixCSC{Float64, Int}, b, u,
67+
function LinearSolve.init_cacheval(
68+
alg::UMFPACKFactorization, A::SparseMatrixCSC{Float64, Int}, b, u,
6569
Pl, Pr,
6670
maxiters::Int, abstol, reltol,
6771
verbose::Bool, assumptions::OperatorAssumptions)
6872
PREALLOCATED_UMFPACK
6973
end
7074

71-
function LinearSolve.init_cacheval(alg::UMFPACKFactorization, A::AbstractSparseArray, b, u, Pl, Pr,
75+
function LinearSolve.init_cacheval(
76+
alg::UMFPACKFactorization, A::AbstractSparseArray, b, u, Pl, Pr,
7277
maxiters::Int, abstol,
7378
reltol,
7479
verbose::Bool, assumptions::OperatorAssumptions)
@@ -78,7 +83,8 @@ function LinearSolve.init_cacheval(alg::UMFPACKFactorization, A::AbstractSparseA
7883
rowvals(A), nonzeros(A)))
7984
end
8085

81-
function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::UMFPACKFactorization; kwargs...)
86+
function SciMLBase.solve!(
87+
cache::LinearSolve.LinearCache, alg::UMFPACKFactorization; kwargs...)
8288
A = cache.A
8389
A = convert(AbstractMatrix, A)
8490
if cache.isfresh
@@ -116,14 +122,16 @@ end
116122
const PREALLOCATED_KLU = KLU.KLUFactorization(SparseMatrixCSC(0, 0, [1], Int[],
117123
Float64[]))
118124

119-
function LinearSolve.init_cacheval(alg::KLUFactorization, A::SparseMatrixCSC{Float64, Int}, b, u, Pl,
125+
function LinearSolve.init_cacheval(
126+
alg::KLUFactorization, A::SparseMatrixCSC{Float64, Int}, b, u, Pl,
120127
Pr,
121128
maxiters::Int, abstol, reltol,
122129
verbose::Bool, assumptions::OperatorAssumptions)
123130
PREALLOCATED_KLU
124131
end
125132

126-
function LinearSolve.init_cacheval(alg::KLUFactorization, A::AbstractSparseArray, b, u, Pl, Pr,
133+
function LinearSolve.init_cacheval(
134+
alg::KLUFactorization, A::AbstractSparseArray, b, u, Pl, Pr,
127135
maxiters::Int, abstol,
128136
reltol,
129137
verbose::Bool, assumptions::OperatorAssumptions)
@@ -182,7 +190,7 @@ function LinearSolve.init_cacheval(alg::NormalCholeskyFactorization,
182190
Symmetric{<:Number, <:AbstractSparseArray}}, b, u, Pl, Pr,
183191
maxiters::Int, abstol, reltol, verbose::Bool,
184192
assumptions::OperatorAssumptions)
185-
LinearSolve.ArrayInterface.cholesky_instance(convert(AbstractMatrix, A))
193+
LinearSolve.ArrayInterface.cholesky_instance(convert(AbstractMatrix, A))
186194
end
187195

188196
# Specialize QR for the non-square case
@@ -221,7 +229,8 @@ function pattern_changed(fact, A::SparseArrays.SparseMatrixCSC)
221229
fact.rowval)
222230
end
223231

224-
function LinearSolve.defaultalg(A::AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti}, b,
232+
function LinearSolve.defaultalg(
233+
A::AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti}, b,
225234
assump::OperatorAssumptions{Bool}) where {Ti}
226235
if assump.issq
227236
if length(b) <= 10_000 && length(nonzeros(A)) / length(A) < 2e-4
@@ -242,4 +251,4 @@ LinearSolve.PrecompileTools.@compile_workload begin
242251
sol = solve(prob, UMFPACKFactorization())
243252
end
244253

245-
end
254+
end

ext/LinearSolveSparspakExt.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ using SparseArrays: AbstractSparseMatrixCSC, nonzeros, rowvals, getcolptr
88
const PREALLOCATED_SPARSEPAK = sparspaklu(SparseMatrixCSC(0, 0, [1], Int[], Float64[]),
99
factorize = false)
1010

11-
function LinearSolve.init_cacheval(::SparspakFactorization, A::SparseMatrixCSC{Float64, Int}, b, u, Pl,
11+
function LinearSolve.init_cacheval(
12+
::SparspakFactorization, A::SparseMatrixCSC{Float64, Int}, b, u, Pl,
1213
Pr, maxiters::Int, abstol,
1314
reltol,
1415
verbose::Bool, assumptions::OperatorAssumptions)
1516
PREALLOCATED_SPARSEPAK
1617
end
1718

18-
function LinearSolve.init_cacheval(::SparspakFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol,
19+
function LinearSolve.init_cacheval(
20+
::SparspakFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol,
1921
reltol,
2022
verbose::Bool, assumptions::OperatorAssumptions)
2123
A = convert(AbstractMatrix, A)
@@ -30,7 +32,8 @@ function LinearSolve.init_cacheval(::SparspakFactorization, A, b, u, Pl, Pr, max
3032
end
3133
end
3234

33-
function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::SparspakFactorization; kwargs...)
35+
function SciMLBase.solve!(
36+
cache::LinearSolve.LinearCache, alg::SparspakFactorization; kwargs...)
3437
A = cache.A
3538
if cache.isfresh
3639
if cache.cacheval !== nothing && alg.reuse_symbolic
@@ -56,4 +59,4 @@ LinearSolve.PrecompileTools.@compile_workload begin
5659
sol = solve(prob, SparspakFactorization())
5760
end
5861

59-
end
62+
end

0 commit comments

Comments
 (0)