Skip to content

Commit 69437f4

Browse files
Format files with SciMLStyle
1 parent b85c233 commit 69437f4

17 files changed

Lines changed: 975 additions & 845 deletions

lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,40 @@ import ArrayInterface: fast_scalar_indexing, zeromatrix, lu_instance
2020
# import StaticArrayInterface
2121
import StaticArrays
2222
import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA,
23-
StaticMatrix
23+
StaticMatrix
2424

2525
using DiffEqBase: TimeGradientWrapper,
26-
UJacobianWrapper, TimeDerivativeWrapper,
27-
UDerivativeWrapper
28-
import SciMLBase: SciMLBase, constructorof, @set, isinplace, has_jvp, unwrapped_f, DEIntegrator, ODEFunction, SplitFunction, DynamicalODEFunction, DAEFunction, islinear, remake, solve!, isconstant
26+
UJacobianWrapper, TimeDerivativeWrapper,
27+
UDerivativeWrapper
28+
import SciMLBase: SciMLBase, constructorof, @set, isinplace, has_jvp, unwrapped_f,
29+
DEIntegrator, ODEFunction, SplitFunction, DynamicalODEFunction,
30+
DAEFunction, islinear, remake, solve!, isconstant
2931
using SciMLBase: @set, @reset
30-
import SciMLOperators: SciMLOperators, IdentityOperator, update_coefficients, update_coefficients!, MatrixOperator, AbstractSciMLOperator, ScalarOperator
31-
import SparseMatrixColorings: ConstantColoringAlgorithm, GreedyColoringAlgorithm, ColoringProblem,
32-
ncolors, column_colors, coloring, sparsity_pattern
32+
import SciMLOperators: SciMLOperators, IdentityOperator, update_coefficients,
33+
update_coefficients!, MatrixOperator, AbstractSciMLOperator,
34+
ScalarOperator
35+
import SparseMatrixColorings: ConstantColoringAlgorithm, GreedyColoringAlgorithm,
36+
ColoringProblem,
37+
ncolors, column_colors, coloring, sparsity_pattern
3338
import OrdinaryDiffEqCore
3439
using OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveImplicitAlgorithm,
35-
DAEAlgorithm,
36-
OrdinaryDiffEqImplicitAlgorithm, CompositeAlgorithm,
37-
OrdinaryDiffEqExponentialAlgorithm,
38-
OrdinaryDiffEqAdaptiveExponentialAlgorithm,
39-
AbstractNLSolver, nlsolve_f, issplit,
40-
concrete_jac, unwrap_alg, OrdinaryDiffEqCache, _vec, standardtag,
41-
isnewton, _unwrap_val,
42-
set_new_W!, set_W_γdt!, alg_difftype, unwrap_cache, diffdir,
43-
get_W, isfirstcall, isfirststage, isJcurrent,
44-
get_new_W_γdt_cutoff, isWmethod,
45-
TryAgain, DIRK, COEFFICIENT_MULTISTEP, NORDSIECK_MULTISTEP, GLM,
46-
FastConvergence, Convergence, SlowConvergence,
47-
VerySlowConvergence, Divergence, NLStatus, MethodType, constvalue, @SciMLMessage
40+
DAEAlgorithm,
41+
OrdinaryDiffEqImplicitAlgorithm, CompositeAlgorithm,
42+
OrdinaryDiffEqExponentialAlgorithm,
43+
OrdinaryDiffEqAdaptiveExponentialAlgorithm,
44+
AbstractNLSolver, nlsolve_f, issplit,
45+
concrete_jac, unwrap_alg, OrdinaryDiffEqCache, _vec, standardtag,
46+
isnewton, _unwrap_val,
47+
set_new_W!, set_W_γdt!, alg_difftype, unwrap_cache, diffdir,
48+
get_W, isfirstcall, isfirststage, isJcurrent,
49+
get_new_W_γdt_cutoff, isWmethod,
50+
TryAgain, DIRK, COEFFICIENT_MULTISTEP, NORDSIECK_MULTISTEP, GLM,
51+
FastConvergence, Convergence, SlowConvergence,
52+
VerySlowConvergence, Divergence, NLStatus, MethodType, constvalue,
53+
@SciMLMessage
4854

4955
import OrdinaryDiffEqCore: get_chunksize, resize_J_W!, resize_nlsolver!, alg_autodiff,
50-
_get_fwd_tag
56+
_get_fwd_tag
5157

5258
import ConstructionBase
5359
using ConstructionBase: constructorof
@@ -79,10 +85,18 @@ function get_nzval end
7985
function set_all_nzval! end
8086

8187
# Provide error messages if these are called without extension
82-
nonzeros(A) = error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
83-
spzeros(args...) = error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
84-
get_nzval(A) = error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
85-
set_all_nzval!(A, val) = error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
88+
function nonzeros(A)
89+
error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
90+
end
91+
function spzeros(args...)
92+
error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
93+
end
94+
function get_nzval(A)
95+
error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
96+
end
97+
function set_all_nzval!(A, val)
98+
error("SparseArrays extension not loaded. Please load SparseArrays to use sparse matrix functionality.")
99+
end
86100

87101
include("alg_utils.jl")
88102
include("linsolve_utils.jl")

lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ _alg_autodiff(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = alg
1010
_alg_autodiff(alg::CompositeAlgorithm) = _alg_autodiff(alg.algs[end])
1111
function _alg_autodiff(
1212
alg::Union{
13-
OrdinaryDiffEqExponentialAlgorithm{CS, AD},
14-
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD},
15-
}
16-
) where {
17-
CS, AD,
18-
}
13+
OrdinaryDiffEqExponentialAlgorithm{CS, AD},
14+
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}
15+
}
16+
) where {
17+
CS, AD
18+
}
1919
return alg.autodiff
2020
end
2121

@@ -46,27 +46,27 @@ function DiffEqBase.prepare_alg(
4646
alg::Union{
4747
OrdinaryDiffEqAdaptiveImplicitAlgorithm{
4848
CS, AD,
49-
FDT,
49+
FDT
5050
},
5151
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT},
5252
DAEAlgorithm{CS, AD, FDT},
53-
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT},
53+
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT}
5454
},
5555
u0::AbstractArray{T},
5656
p, prob
57-
) where {CS, AD, FDT, T}
57+
) where {CS, AD, FDT, T}
5858
prepped_AD = prepare_ADType(alg_autodiff(alg), prob, u0, p, standardtag(alg))
5959

6060
sparse_prepped_AD = prepare_user_sparsity(prepped_AD, prob)
6161

6262
# if u0 is a StaticArray or eltype is Complex etc. don't use sparsity
6363
if (
64-
(
65-
(typeof(u0) <: StaticArray) || (eltype(u0) <: Complex) ||
66-
(!(prob.f isa DAEFunction) && prob.f.mass_matrix isa MatrixOperator)
67-
) &&
68-
sparse_prepped_AD isa AutoSparse
69-
)
64+
(
65+
(typeof(u0) <: StaticArray) || (eltype(u0) <: Complex) ||
66+
(!(prob.f isa DAEFunction) && prob.f.mass_matrix isa MatrixOperator)
67+
) &&
68+
sparse_prepped_AD isa AutoSparse
69+
)
7070
@warn "Input type or problem definition is incompatible with sparse automatic differentiation. Switching to using dense automatic differentiation."
7171
autodiff = ADTypes.dense_ad(sparse_prepped_AD)
7272
else
@@ -96,12 +96,12 @@ function prepare_ADType(autodiff_alg::AutoForwardDiff, prob, u0, p, standardtag)
9696
cs = fwd_cs == 0 ? nothing : fwd_cs
9797

9898
if (
99-
(
100-
prob.f isa ODEFunction &&
101-
prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper
102-
) ||
103-
(isbitstype(T) && sizeof(T) > 24)
104-
) && (cs == 0 || isnothing(cs))
99+
(
100+
prob.f isa ODEFunction &&
101+
prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper
102+
) ||
103+
(isbitstype(T) && sizeof(T) > 24)
104+
) && (cs == 0 || isnothing(cs))
105105
return AutoForwardDiff{1}(tag)
106106
else
107107
return AutoForwardDiff{cs}(tag)
@@ -112,9 +112,9 @@ function prepare_ADType(alg::AutoFiniteDiff, prob, u0, p, standardtag)
112112
# If the autodiff alg is AutoFiniteDiff, prob.f.f isa FunctionWrappersWrapper,
113113
# and fdtype is complex, fdtype needs to change to something not complex
114114
if alg.fdtype == Val{:complex}() && (
115-
prob.f isa ODEFunction &&
116-
prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper
117-
)
115+
prob.f isa ODEFunction &&
116+
prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper
117+
)
118118
@warn "AutoFiniteDiff fdtype complex is not compatible with this function"
119119
return AutoFiniteDiff(fdtype = Val{:forward}())
120120
end
@@ -152,9 +152,9 @@ function prepare_user_sparsity(ad_alg, prob)
152152
sparsity = sparsity isa MatrixOperator ? sparsity.A : sparsity
153153

154154
color_alg = SciMLBase.has_colorvec(prob.f) ?
155-
ConstantColoringAlgorithm(
156-
sparsity, prob.f.colorvec
157-
) : GreedyColoringAlgorithm()
155+
ConstantColoringAlgorithm(
156+
sparsity, prob.f.colorvec
157+
) : GreedyColoringAlgorithm()
158158

159159
sparsity_detector = ADTypes.KnownJacobianSparsityDetector(sparsity)
160160

0 commit comments

Comments
 (0)