Skip to content

Commit 900d817

Browse files
committed
Format code with JuliaFormatter v2.1.5
Applied JuliaFormatter to ensure consistent code formatting across the entire codebase. This includes formatting improvements to source files, documentation, and test files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5eafe25 commit 900d817

File tree

22 files changed

+406
-351
lines changed

22 files changed

+406
-351
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Let `M`, `D`, `F` be matrix-based, diagonal-matrix-based, and function-based
4747
```@example operator_algebra
4848
using SciMLOperators, LinearAlgebra
4949
N = 4
50-
function f(v, u, p, t)
50+
function f(v, u, p, t)
5151
u .* v
5252
end
53-
function f(w, v, u, p, t)
53+
function f(w, v, u, p, t)
5454
w .= u .* v
5555
end
5656

docs/pages.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ pages = [
66
"FFT Tutorial" => "tutorials/fftw.md"
77
],
88
"interface.md",
9-
"Premade Operators" => "premade_operators.md",
10-
11-
]
9+
"Premade Operators" => "premade_operators.md"]

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ act like “normal” functions for equation solvers. For example, if `A(v,u,p,t
4848
has the same operation as `update_coefficients(A, u, p, t); A * v`, then `A`
4949
can be used in any place where a differential equation definition
5050
`(u,p,t) -> A(u, u, p, t)` is used without requiring the user or solver to do any extra
51-
work.
51+
work.
5252

5353
Another example is state-dependent mass matrices. `M(u,p,t)*u' = f(u,p,t)`.
5454
When solving such an equation, the solver must understand how to "update M"
@@ -66,7 +66,7 @@ an extended operator interface with all of these properties, hence the
6666
`AbstractSciMLOperator` interface.
6767

6868
!!! warn
69-
69+
7070
This means that LinearMaps.jl is fundamentally lacking and is incompatible
7171
with many of the tools in the SciML ecosystem, except for the specific cases
7272
where the matrix-free operator is a constant!

docs/src/tutorials/getting_started.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ and updating operators.
1111
Before we get into the deeper operators, let's show the simplest SciMLOperator:
1212
`MatrixOperator`. `MatrixOperator` just turns a matrix into an `AbstractSciMLOperator`,
1313
so it's not really a matrix-free operator but it's a starting point that is good for
14-
understanding the interface and testing. To create a `MatrixOperator`, simply call the
14+
understanding the interface and testing. To create a `MatrixOperator`, simply call the
1515
constructor on a matrix:
1616

1717
```@example getting_started
1818
using SciMLOperators, LinearAlgebra
19-
A = [-2.0 1 0 0 0
20-
1 -2 1 0 0
21-
0 1 -2 1 0
22-
0 0 1 -2 1
23-
0 0 0 1 -2]
19+
A = [-2.0 1 0 0 0
20+
1 -2 1 0 0
21+
0 1 -2 1 0
22+
0 0 1 -2 1
23+
0 0 0 1 -2]
2424
2525
opA = MatrixOperator(A)
2626
```
@@ -29,7 +29,7 @@ The operators can do [operations as defined in the operator interface](@ref oper
2929
matrix multiplication as the core action:
3030

3131
```@example getting_started
32-
v = [3.0,2.0,1.0,2.0,3.0]
32+
v = [3.0, 2.0, 1.0, 2.0, 3.0]
3333
opA*v
3434
```
3535

@@ -43,7 +43,8 @@ mul!(w, opA, v)
4343
```
4444

4545
```@example getting_started
46-
α = 1.0; β = 1.0
46+
α = 1.0;
47+
β = 1.0
4748
mul!(w, opA, v, α, β) # α*opA*v + β*w
4849
```
4950

@@ -64,18 +65,20 @@ For example, let's make the operator `A .* u + dt*I` where `dt` is a parameter
6465
and `u` is a state vector:
6566

6667
```@example getting_started
67-
A = [-2.0 1 0 0 0
68-
1 -2 1 0 0
69-
0 1 -2 1 0
70-
0 0 1 -2 1
71-
0 0 0 1 -2]
68+
A = [-2.0 1 0 0 0
69+
1 -2 1 0 0
70+
0 1 -2 1 0
71+
0 0 1 -2 1
72+
0 0 0 1 -2]
7273
7374
function update_function!(B, u, p, t)
7475
dt = p
7576
B .= A .* u + dt*I
7677
end
7778
78-
u = Array(1:1.0:5); p = 0.1; t = 0.0
79+
u = Array(1:1.0:5);
80+
p = 0.1;
81+
t = 0.0
7982
opB = MatrixOperator(copy(A); update_func! = update_function!)
8083
```
8184

@@ -123,18 +126,18 @@ With `FunctionOperator`, we directly define the operator application function `o
123126
which means `w = opA(u,p,t)*v`. For example we can do the following:
124127

125128
```@example getting_started
126-
function Afunc!(w,v,u,p,t)
129+
function Afunc!(w, v, u, p, t)
127130
w[1] = -2v[1] + v[2]
128131
for i in 2:4
129-
w[i] = v[i-1] - 2v[i] + v[i+1]
132+
w[i] = v[i - 1] - 2v[i] + v[i + 1]
130133
end
131134
w[5] = v[4] - 2v[5]
132135
nothing
133136
end
134137
135-
function Afunc!(v,u,p,t)
138+
function Afunc!(v, u, p, t)
136139
w = zeros(5)
137-
Afunc!(w,v,u,p,t)
140+
Afunc!(w, v, u, p, t)
138141
w
139142
end
140143
@@ -148,29 +151,29 @@ mfopA*v - opA*v
148151
```
149152

150153
```@example getting_started
151-
mfopA(v,u,p,t) - opA(v,u,p,t)
154+
mfopA(v, u, p, t) - opA(v, u, p, t)
152155
```
153156

154157
We can also create the state-dependent operator as well:
155158

156159
```@example getting_started
157-
function Bfunc!(w,v,u,p,t)
160+
function Bfunc!(w, v, u, p, t)
158161
dt = p
159162
w[1] = -(2*u[1]-dt)*v[1] + v[2]*u[1]
160163
for i in 2:4
161-
w[i] = v[i-1]*u[i] - (2*u[i]-dt)*v[i] + v[i+1]*u[i]
164+
w[i] = v[i - 1]*u[i] - (2*u[i]-dt)*v[i] + v[i + 1]*u[i]
162165
end
163166
w[5] = v[4]*u[5] - (2*u[5]-dt)*v[5]
164167
nothing
165168
end
166169
167-
function Bfunc!(v,u,p,t)
170+
function Bfunc!(v, u, p, t)
168171
w = zeros(5)
169-
Bfunc!(w,v,u,p,t)
172+
Bfunc!(w, v, u, p, t)
170173
w
171174
end
172175
173-
mfopB = FunctionOperator(Bfunc!, zeros(5), zeros(5); u, p, t, isconstant=false)
176+
mfopB = FunctionOperator(Bfunc!, zeros(5), zeros(5); u, p, t, isconstant = false)
174177
```
175178

176179
```@example getting_started
@@ -187,19 +190,19 @@ operator for `A .* u` (since right now there is not a built in operator for vect
187190
but that would be a fantastic thing to add!):
188191

189192
```@example getting_started
190-
function Cfunc!(w,v,u,p,t)
193+
function Cfunc!(w, v, u, p, t)
191194
w[1] = -2v[1] + v[2]
192195
for i in 2:4
193-
w[i] = v[i-1] - 2v[i] + v[i+1]
196+
w[i] = v[i - 1] - 2v[i] + v[i + 1]
194197
end
195198
w[5] = v[4] - 2v[5]
196199
w .= w .* u
197200
nothing
198201
end
199202
200-
function Cfunc!(v,u,p,t)
203+
function Cfunc!(v, u, p, t)
201204
w = zeros(5)
202-
Cfunc!(w,v,u,p,t)
205+
Cfunc!(w, v, u, p, t)
203206
w
204207
end
205208
@@ -227,11 +230,11 @@ adjoints, inverses, and more. For more information, see the [operator algebras t
227230
Great! You now know how to be state/parameter/time-dependent operators and make them matrix-free, along with
228231
doing algebras on operators. What's next?
229232

230-
* Interested in more examples of building operators? See the example of [making a fast fourier transform linear operator](@ref fft)
231-
* Interested in more operators ready to go? See the [Premade Operators page](@ref premade_operators) for all of the operators included with SciMLOperators. Note that there are also downstream packages that make new operators.
232-
* Want to make your own SciMLOperator? See the [AbstractSciMLOperator interface page](@ref operator_interface) which describes the full interface.
233+
- Interested in more examples of building operators? See the example of [making a fast fourier transform linear operator](@ref fft)
234+
- Interested in more operators ready to go? See the [Premade Operators page](@ref premade_operators) for all of the operators included with SciMLOperators. Note that there are also downstream packages that make new operators.
235+
- Want to make your own SciMLOperator? See the [AbstractSciMLOperator interface page](@ref operator_interface) which describes the full interface.
233236

234237
How do you use SciMLOperators? Check out the following downstream pages:
235238

236-
* [Using SciMLOperators in LinearSolve.jl for matrix-free Krylov methods](https://docs.sciml.ai/LinearSolve/stable/tutorials/linear/)
237-
* [Using SciMLOperators in OrdinaryDiffEq.jl for semi-linear ODE solvers](https://docs.sciml.ai/DiffEqDocs/stable/solvers/nonautonomous_linear_ode/)
239+
- [Using SciMLOperators in LinearSolve.jl for matrix-free Krylov methods](https://docs.sciml.ai/LinearSolve/stable/tutorials/linear/)
240+
- [Using SciMLOperators in OrdinaryDiffEq.jl for semi-linear ODE solvers](https://docs.sciml.ai/DiffEqDocs/stable/solvers/nonautonomous_linear_ode/)

docs/src/tutorials/operator_algebras.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ in order to build more complex objects and using their operations.
77
```@example operator_algebra
88
using SciMLOperators, LinearAlgebra
99
N = 4
10-
function f(v, u, p, t)
10+
function f(v, u, p, t)
1111
u .* v
1212
end
13-
function f(w, v, u, p, t)
13+
function f(w, v, u, p, t)
1414
w .= u .* v
1515
end
1616

src/SciMLOperators.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ the following type of equation:
3838
w = L(u,p,t)[v]
3939
```
4040
41-
where `L[v]` is the operator application of ``L`` on the vector ``v``.
41+
where `L[v]` is the operator application of ``L`` on the vector ``v``.
4242
4343
## Interface
4444
4545
An `AbstractSciMLOperator` can be called like a function in the following ways:
4646
47-
- `L(v, u, p, t)` - Out-of-place application where `v` is the action vector and `u` is the update vector
48-
- `L(w, v, u, p, t)` - In-place application where `w` is the destination, `v` is the action vector, and `u` is the update vector
49-
- `L(w, v, u, p, t, α, β)` - In-place application with scaling: `w = α*(L*v) + β*w`
47+
- `L(v, u, p, t)` - Out-of-place application where `v` is the action vector and `u` is the update vector
48+
- `L(w, v, u, p, t)` - In-place application where `w` is the destination, `v` is the action vector, and `u` is the update vector
49+
- `L(w, v, u, p, t, α, β)` - In-place application with scaling: `w = α*(L*v) + β*w`
5050
5151
Operator state can be updated separately from application:
5252
53-
- `update_coefficients!(L, u, p, t)` for in-place operator update
54-
- `L = update_coefficients(L, u, p, t)` for out-of-place operator update
53+
- `update_coefficients!(L, u, p, t)` for in-place operator update
54+
- `L = update_coefficients(L, u, p, t)` for out-of-place operator update
5555
5656
SciMLOperators also overloads `Base.*`, `LinearAlgebra.mul!`,
5757
`LinearAlgebra.ldiv!` for operator evaluation without updating operator state.
@@ -186,7 +186,6 @@ M = MatrixOperator(zero(N, N); update_func = mat_update_func,
186186
M(v, u, p, t) == zeros(N) # true
187187
M(v, u, p, t; scale = 1.0) != zero(N)
188188
```
189-
190189
"""
191190
abstract type AbstractSciMLOperator{T} end
192191

src/basic.jl

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ function (ii::IdentityOperator)(v::AbstractVecOrMat, u, p, t; kwargs...)
7777
end
7878

7979
# In-place: w is destination, v is action vector, u is update vector
80-
@inline function (ii::IdentityOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
80+
@inline function (ii::IdentityOperator)(
81+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
8182
@assert size(v, 1) == ii.len
8283
copy!(w, v)
8384
end
8485

8586
# In-place with scaling: w = α*(ii*v) + β*w
86-
@inline function (ii::IdentityOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
87+
@inline function (ii::IdentityOperator)(
88+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
8789
@assert size(v, 1) == ii.len
8890
mul!(w, I, v, α, β)
8991
end
@@ -179,7 +181,8 @@ function (nn::NullOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; k
179181
end
180182

181183
# In-place with scaling: w = α*(nn*v) + β*w
182-
function (nn::NullOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
184+
function (nn::NullOperator)(
185+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
183186
@assert size(v, 1) == nn.len
184187
lmul!(β, w)
185188
w
@@ -386,20 +389,21 @@ function (L::ScaledOperator)(v::AbstractVecOrMat, u, p, t; kwargs...)
386389
end
387390

388391
# In-place: w is destination, v is action vector, u is update vector
389-
@inline function (L::ScaledOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
392+
@inline function (L::ScaledOperator)(
393+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
390394
update_coefficients!(L.λ, u, p, t; kwargs...)
391395
a = convert(Number, L.λ)
392396
return L.L(w, v, u, p, t, a, false; kwargs...)
393397
end
394398

395399
# In-place with scaling: w = α*(L*v) + β*w
396-
@inline function (L::ScaledOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
400+
@inline function (L::ScaledOperator)(
401+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
397402
update_coefficients!(L.λ, u, p, t; kwargs...)
398403
a = convert(Number, L.λ * α)
399404
return L.L(w, v, u, p, t, a, β; kwargs...)
400405
end
401406

402-
403407
"""
404408
Lazy operator addition
405409
@@ -610,7 +614,8 @@ function (L::AddedOperator)(v::AbstractVecOrMat, u, p, t; kwargs...)
610614
end
611615

612616
# In-place: w is destination, v is action vector, u is update vector
613-
@generated function (L::AddedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
617+
@generated function (L::AddedOperator)(
618+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
614619
# We don't need to update coefficients of L, as op(w, v, u, p, t) will do it for each op
615620

616621
ops_types = L.parameters[2].parameters
@@ -619,15 +624,16 @@ end
619624
quote
620625
L.ops[1](w, v, u, p, t; kwargs...)
621626
Base.@nexprs $N i->begin
622-
op = L.ops[i+1]
627+
op = L.ops[i + 1]
623628
op(w, v, u, p, t, true, true; kwargs...)
624629
end
625630
w
626631
end
627632
end
628633

629634
# In-place with scaling: w = α*(L*v) + β*w
630-
@generated function (L::AddedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
635+
@generated function (L::AddedOperator)(
636+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
631637
# We don't need to update coefficients of L, as op(w, v, u, p, t) will do it for each op
632638

633639
T = L.parameters[1]
@@ -637,7 +643,7 @@ end
637643
quote
638644
L.ops[1](w, v, u, p, t, α, β; kwargs...)
639645
Base.@nexprs $N i->begin
640-
op = L.ops[i+1]
646+
op = L.ops[i + 1]
641647
op(w, v, u, p, t, α, true; kwargs...)
642648
end
643649
w
@@ -909,22 +915,23 @@ end
909915
function (L::ComposedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
910916
update_coefficients!(L, u, p, t; kwargs...)
911917
@assert iscached(L) "Cache needs to be set up for ComposedOperator. Call cache_operator(L, u) first."
912-
913-
vecs = (w, L.cache[1:(end-1)]..., v)
918+
919+
vecs = (w, L.cache[1:(end - 1)]..., v)
914920
for i in reverse(1:length(L.ops))
915-
L.ops[i](vecs[i], vecs[i+1], u, p, t; kwargs...)
921+
L.ops[i](vecs[i], vecs[i + 1], u, p, t; kwargs...)
916922
end
917923
w
918924
end
919925

920926
# In-place with scaling: w = α*(L*v) + β*w
921-
function (L::ComposedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
927+
function (L::ComposedOperator)(
928+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
922929
update_coefficients!(L, u, p, t; kwargs...)
923930
@assert iscached(L) "Cache needs to be set up for ComposedOperator. Call cache_operator(L, u) first."
924-
931+
925932
cache = L.cache[end]
926933
copy!(cache, w)
927-
934+
928935
L(w, v, u, p, t; kwargs...)
929936
lmul!(α, w)
930937
axpy!(β, cache, w)
@@ -1063,10 +1070,11 @@ function (L::InvertedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t
10631070
end
10641071

10651072
# In-place with scaling: w = α*(L*v) + β*w
1066-
function (L::InvertedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
1073+
function (L::InvertedOperator)(
1074+
w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
10671075
update_coefficients!(L, u, p, t; kwargs...)
10681076
@assert iscached(L) "Cache needs to be set up for InvertedOperator. Call cache_operator(L, u) first."
1069-
1077+
10701078
copy!(L.cache, w)
10711079
ldiv!(w, L.L, v)
10721080
lmul!(α, w)

0 commit comments

Comments
 (0)