Skip to content

Commit 49aebc6

Browse files
Format
1 parent b0e9d62 commit 49aebc6

File tree

22 files changed

+431
-364
lines changed

22 files changed

+431
-364
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 exmaple 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: 3 additions & 3 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
@@ -56,4 +56,4 @@ L4 = cache_operator(L4, u)
5656
# allocation-free evaluation
5757
L2(w, v, u, p, t) # == mul!(w, L2, v)
5858
L4(w, v, u, p, t, α, β) # == mul!(w, L4, v, α, β)
59-
```
59+
```

src/SciMLOperators.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ the following type of equation:
3535
w = L(u,p,t)[v]
3636
```
3737
38-
where `L[v]` is the operator application of ``L`` on the vector ``v``.
38+
where `L[v]` is the operator application of ``L`` on the vector ``v``.
3939
4040
## Interface
4141
4242
An `AbstractSciMLOperator` can be called like a function in the following ways:
4343
44-
- `L(v, u, p, t)` - Out-of-place application where `v` is the action vector and `u` is the update vector
45-
- `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
46-
- `L(w, v, u, p, t, α, β)` - In-place application with scaling: `w = α*(L*v) + β*w`
44+
- `L(v, u, p, t)` - Out-of-place application where `v` is the action vector and `u` is the update vector
45+
- `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
46+
- `L(w, v, u, p, t, α, β)` - In-place application with scaling: `w = α*(L*v) + β*w`
4747
4848
Operator state can be updated separately from application:
4949
50-
- `update_coefficients!(L, u, p, t)` for in-place operator update
51-
- `L = update_coefficients(L, u, p, t)` for out-of-place operator update
50+
- `update_coefficients!(L, u, p, t)` for in-place operator update
51+
- `L = update_coefficients(L, u, p, t)` for out-of-place operator update
5252
5353
SciMLOperators also overloads `Base.*`, `LinearAlgebra.mul!`,
5454
`LinearAlgebra.ldiv!` for operator evaluation without updating operator state.
@@ -183,7 +183,6 @@ M = MatrixOperator(zero(N, N); update_func = mat_update_func,
183183
M(v, u, p, t) == zeros(N) # true
184184
M(v, u, p, t; scale = 1.0) != zero(N)
185185
```
186-
187186
"""
188187
abstract type AbstractSciMLOperator{T} end
189188

0 commit comments

Comments
 (0)