Skip to content

Commit 451c583

Browse files
Merge pull request #224 from avik-pal/ap/format
Run formatter
2 parents 3b40f1b + 4a1d0c3 commit 451c583

27 files changed

+1477
-1371
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Manifest.toml
2626
# Editor generatoed file
2727
.*.swp
2828
.*.swo
29+
.vscode

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![codecov](https://codecov.io/gh/SciML/SciMLOperators.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SciML/SciMLOperators.jl)
99
[![Build Status](https://github.com/SciML/SciMLOperators.jl/workflows/CI/badge.svg)](https://github.com/SciML/SciMLOperators.jl/actions?query=workflow%3ACI)
1010

11-
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
11+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
1212
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
1313

1414
`SciMLOperators` is a package for managing linear, nonlinear,
@@ -28,6 +28,7 @@ or `NonlinearSolve.jl` as a linear/nonlinear operator, or to
2828
`SciML` ecosystem are provided in the documentation.
2929

3030
## Installation
31+
3132
`SciMLOperators.jl` is a registerd package and can be installed via
3233

3334
```
@@ -69,7 +70,7 @@ t = 0.0 # time
6970
u = rand(N)
7071
v = L1(u, p, t) # == L1 * u
7172

72-
u_kron = rand(N ^ 3)
73+
u_kron = rand(N^3)
7374
v_kron = L3(u_kron, p, t) # == L3 * u_kron
7475
```
7576

@@ -90,9 +91,9 @@ L4(v, u, p, t, α, β) # == mul!(v, L4, u, α, β)
9091

9192
## Roadmap
9293

93-
- [ ] [Complete integration with `SciML` ecosystem](https://github.com/SciML/SciMLOperators.jl/issues/142)
94-
- [ ] [Block-matrices](https://github.com/SciML/SciMLOperators.jl/issues/161)
95-
- [x] [Benchmark and speed-up tensorbproduct evaluations](https://github.com/SciML/SciMLOperators.jl/issues/58)
96-
- [ ] [Fast tensor-sum (`kronsum`) evaluation](https://github.com/SciML/SciMLOperators.jl/issues/53)
97-
- [ ] [Fully flesh out operator array algebra](https://github.com/SciML/SciMLOperators.jl/issues/62)
98-
- [ ] [Operator fusion/matrix chain multiplication at constant `(u, p, t)`-slices](https://github.com/SciML/SciMLOperators.jl/issues/51)
94+
- [ ] [Complete integration with `SciML` ecosystem](https://github.com/SciML/SciMLOperators.jl/issues/142)
95+
- [ ] [Block-matrices](https://github.com/SciML/SciMLOperators.jl/issues/161)
96+
- [x] [Benchmark and speed-up tensorbproduct evaluations](https://github.com/SciML/SciMLOperators.jl/issues/58)
97+
- [ ] [Fast tensor-sum (`kronsum`) evaluation](https://github.com/SciML/SciMLOperators.jl/issues/53)
98+
- [ ] [Fully flesh out operator array algebra](https://github.com/SciML/SciMLOperators.jl/issues/62)
99+
- [ ] [Operator fusion/matrix chain multiplication at constant `(u, p, t)`-slices](https://github.com/SciML/SciMLOperators.jl/issues/51)

benchmarks/tensor.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ using SciMLOperators: IdentityOperator, ⊗
44
N = 12
55
K = 100
66
Id = IdentityOperator(N)
7-
A = rand(N,N)
8-
B = rand(N,N)
9-
C = rand(N,N)
7+
A = rand(N, N)
8+
B = rand(N, N)
9+
C = rand(N, N)
1010

1111
println("#===============================#")
1212
println("2D Tensor Products")

docs/make.jl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
55

66
include("pages.jl")
77

8-
makedocs(
9-
sitename="SciMLOperators.jl",
10-
authors="Vedant Puri, Alex Jones, Chris Rackauckas",
11-
modules=[SciMLOperators],
12-
clean=true, doctest=false, linkcheck = true,
8+
makedocs(sitename = "SciMLOperators.jl",
9+
authors = "Vedant Puri, Alex Jones, Chris Rackauckas",
10+
modules = [SciMLOperators],
11+
clean = true, doctest = false, linkcheck = true,
1312
warnonly = [:docs_block, :missing_docs, :cross_references, :linkcheck],
14-
format = Documenter.HTML(
15-
assets = ["assets/favicon.ico"],
16-
canonical="https://docs.sciml.ai/SciMLOperators/stable"),
17-
pages=pages
18-
)
13+
format = Documenter.HTML(assets = ["assets/favicon.ico"],
14+
canonical = "https://docs.sciml.ai/SciMLOperators/stable"),
15+
pages = pages)
1916

20-
deploydocs(
21-
repo = "github.com/SciML/SciMLOperators.jl.git";
22-
push_preview = true
23-
)
17+
deploydocs(repo = "github.com/SciML/SciMLOperators.jl.git";
18+
push_preview = true)

docs/pages.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
pages = [
2-
"Home" => "index.md",
3-
"sciml.md",
4-
"interface.md",
5-
"Premade Operators" => "premade_operators.md",
6-
"Tutorials" => Any[
7-
"FFT Tutorial" => "tutorials/fftw.md",
8-
# "tutorials/linear.md",
9-
# "tutorials/nonlin.md",
10-
# "tutorials/ode.md",
11-
# "tutorials/lux.md",
12-
]
13-
]
2+
"Home" => "index.md",
3+
"sciml.md",
4+
"interface.md",
5+
"Premade Operators" => "premade_operators.md",
6+
"Tutorials" => Any["FFT Tutorial" => "tutorials/fftw.md"
7+
# "tutorials/linear.md",
8+
# "tutorials/nonlin.md",
9+
# "tutorials/ode.md",
10+
# "tutorials/lux.md",
11+
],
12+
]

docs/src/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ or `NonlinearSolve.jl` as a linear or nonlinear operator, or to
1616
`OrdinaryDiffEq.jl` as an `ODEFunction`. Examples of usage within the
1717
`SciML` ecosystem are provided in the documentation.
1818

19-
2019
## Installation
2120

2221
To install SciMLOperators.jl, use the Julia package manager:
2322

2423
```julia
2524
using Pkg
2625
Pkg.add("SciMLOperators")
26+
```
2727

2828
## Examples
2929

@@ -58,7 +58,7 @@ t = 0.0 # time
5858
u = rand(N)
5959
v = L1(u, p, t) # == L1 * u
6060

61-
u_kron = rand(N ^ 3)
61+
u_kron = rand(N^3)
6262
v_kron = L3(u_kron, p, t) # == L3 * u_kron
6363
```
6464

@@ -94,13 +94,13 @@ object `p`.
9494

9595
## Features
9696

97-
* Matrix-free operators with `FunctionOperator`
98-
* Fast tensor product evaluation with `TensorProductOperator`
99-
* Lazy algebra: addition, subtraction, multiplication, inverse, adjoint, and transpose
100-
* Couple fast methods for operator evaluation with inversion via `InvertibleOperator`
101-
* One-line API to update operator state depending on arbitrary parameters.
102-
* Mutating and nonmutating update behavior (Zygote compatible)
103-
* One-line API for pre-caching operators for in-place operator evaluations
97+
- Matrix-free operators with `FunctionOperator`
98+
- Fast tensor product evaluation with `TensorProductOperator`
99+
- Lazy algebra: addition, subtraction, multiplication, inverse, adjoint, and transpose
100+
- Couple fast methods for operator evaluation with inversion via `InvertibleOperator`
101+
- One-line API to update operator state depending on arbitrary parameters.
102+
- Mutating and nonmutating update behavior (Zygote compatible)
103+
- One-line API for pre-caching operators for in-place operator evaluations
104104

105105
## Contributing
106106

docs/src/interface.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
These are the formal properties that an `AbstractSciMLOperator` should obey
66
for it to work in the solvers.
77

8-
1. An `AbstractSciMLOperator` represents a linear or nonlinear operator, with input/output
9-
being `AbstractArray`s. Specifically, a SciMLOperator, `L`, of size `(M, N)` accepts an
10-
input argument `u` with leading length `N`, i.e. `size(u, 1) == N`, and returns an
11-
`AbstractArray` of the same dimension with leading length `M`, i.e. `size(L * u, 1) == M`.
12-
2. SciMLOperators can be applied to an `AbstractArray` via overloaded `Base.*`, or
13-
the in-place `LinearAlgebra.mul!`. Additionally, operators are allowed to be time,
14-
or parameter dependent. The state of a SciMLOperator can be updated by calling
15-
the mutating function `update_coefficients!(L, u, p, t)` where `p` represents
16-
parameters, and `t`, time. Calling a SciMLOperator as `L(du, u, p, t)` or out-of-place
17-
`L(u, p, t)` will automatically update the state of `L` before applying it to `u`.
18-
`L(u, p, t)` is the same operation as `L(u, p, t) * u`.
19-
3. To support the update functionality, we have lazily implemented a comprehensive operator
20-
algebra. That means a user can add, subtract, scale, compose and invert SciMLOperators,
21-
and the state of the resultant operator would be updated as expected upon calling
22-
`L(du, u, p, t)` or `L(u, p, t)` so long as an update function is provided for the
23-
component operators.
8+
1. An `AbstractSciMLOperator` represents a linear or nonlinear operator, with input/output
9+
being `AbstractArray`s. Specifically, a SciMLOperator, `L`, of size `(M, N)` accepts an
10+
input argument `u` with leading length `N`, i.e. `size(u, 1) == N`, and returns an
11+
`AbstractArray` of the same dimension with leading length `M`, i.e. `size(L * u, 1) == M`.
12+
2. SciMLOperators can be applied to an `AbstractArray` via overloaded `Base.*`, or
13+
the in-place `LinearAlgebra.mul!`. Additionally, operators are allowed to be time,
14+
or parameter dependent. The state of a SciMLOperator can be updated by calling
15+
the mutating function `update_coefficients!(L, u, p, t)` where `p` represents
16+
parameters, and `t`, time. Calling a SciMLOperator as `L(du, u, p, t)` or out-of-place
17+
`L(u, p, t)` will automatically update the state of `L` before applying it to `u`.
18+
`L(u, p, t)` is the same operation as `L(u, p, t) * u`.
19+
3. To support the update functionality, we have lazily implemented a comprehensive operator
20+
algebra. That means a user can add, subtract, scale, compose and invert SciMLOperators,
21+
and the state of the resultant operator would be updated as expected upon calling
22+
`L(du, u, p, t)` or `L(u, p, t)` so long as an update function is provided for the
23+
component operators.
2424

2525
## Overloaded Traits
2626

@@ -31,9 +31,9 @@ passed to linear solver packages, and even to ordinary differential
3131
equation solvers. The list of overloads to the `AbstractMatrix`
3232
interface includes, but is not limited to, the following:
3333

34-
- `Base: size, zero, one, +, -, *, /, \, ∘, inv, adjoint, transpose, convert`
35-
- `LinearAlgebra: mul!, ldiv!, lmul!, rmul!, factorize, issymmetric, ishermitian, isposdef`
36-
- `SparseArrays: sparse, issparse`
34+
- `Base: size, zero, one, +, -, *, /, \, ∘, inv, adjoint, transpose, convert`
35+
- `LinearAlgebra: mul!, ldiv!, lmul!, rmul!, factorize, issymmetric, ishermitian, isposdef`
36+
- `SparseArrays: sparse, issparse`
3737

3838
## Multidimension arrays and batching
3939

@@ -112,7 +112,7 @@ t = rand()
112112
# in-place update
113113
_A = rand(N, N)
114114
_d = rand(N)
115-
mat_update_func! = (A, u, p, t) -> (copy!(A, _A); lmul!(t, A); nothing)
115+
mat_update_func! = (A, u, p, t) -> (copy!(A, _A); lmul!(t, A); nothing)
116116
diag_update_func! = (diag, u, p, t) -> copy!(diag, N)
117117

118118
M = MatrixOperator(zero(N, N); update_func! = mat_update_func!)
@@ -143,7 +143,7 @@ reason, we allow update functions with arbitrary keyword arguments.
143143
mat_update_func = (A, u, p, t; scale = 0.0) -> scale * (p * p')
144144

145145
M = MatrixOperator(zero(N, N); update_func = mat_update_func,
146-
accepted_kwargs = (:state,))
146+
accepted_kwargs = (:state,))
147147

148148
M(u, p, t) == zeros(N) # true
149149
M(u, p, t; scale = 1.0) != zero(N)
@@ -179,22 +179,22 @@ has_ldiv!
179179
## Note About Affine Operators
180180

181181
Affine operators are operators that have the action `Q*x = A*x + b`. These operators have
182-
no matrix representation, since if there was, it would be a linear operator instead of an
183-
affine operator. You can only represent an affine operator as a linear operator in a
184-
dimension of one larger via the operation: `[A b] * [u;1]`, so it would require something modified
182+
no matrix representation, since if there was, it would be a linear operator instead of an
183+
affine operator. You can only represent an affine operator as a linear operator in a
184+
dimension of one larger via the operation: `[A b] * [u;1]`, so it would require something modified
185185
to the input as well. As such, affine operators are a distinct generalization of linear operators.
186186

187-
While it seems like it might doom the idea of using matrix-free affine operators, it turns out
187+
While it seems like it might doom the idea of using matrix-free affine operators, it turns out
188188
that affine operators can be used in all cases where matrix-free linear solvers are used due to
189-
an easy generalization of the standard convergence proofs. If Q is the affine operator
190-
``Q(x) = Ax + b``, then solving ``Qx = c`` is equivalent to solving ``Ax + b = c`` or ``Ax = c-b``.
191-
If you now do this same “plug-and-chug” handling of the affine operator into the GMRES/CG/etc.
192-
convergence proofs, move the affine part to the rhs residual, and show it converges to solving
193-
``Ax = c-b``, and thus GMRES/CG/etc. solves ``Q(x) = c`` for an affine operator properly.
194-
195-
That same trick can be used mostly anywhere you would've had a linear operator to extend
196-
the proof to affine operators, so then ``exp(A*t)*v`` operations via Krylov methods work for A being
197-
affine as well, and all sorts of things. Thus, affine operators have no matrix representation, but they
189+
an easy generalization of the standard convergence proofs. If Q is the affine operator
190+
``Q(x) = Ax + b``, then solving ``Qx = c`` is equivalent to solving ``Ax + b = c`` or ``Ax = c-b``.
191+
If you now do this same “plug-and-chug” handling of the affine operator into the GMRES/CG/etc.
192+
convergence proofs, move the affine part to the rhs residual, and show it converges to solving
193+
``Ax = c-b``, and thus GMRES/CG/etc. solves ``Q(x) = c`` for an affine operator properly.
194+
195+
That same trick can be used mostly anywhere you would've had a linear operator to extend
196+
the proof to affine operators, so then ``exp(A*t)*v`` operations via Krylov methods work for A being
197+
affine as well, and all sorts of things. Thus, affine operators have no matrix representation, but they
198198
are still compatible with essentially any Krylov method, which would otherwise be compatible with
199199
matrix-free representations, hence their support in the SciMLOperators interface.
200200

@@ -206,14 +206,16 @@ state through arbitrary keyword arguments to `update_coefficients!`. When the ca
206206
For the [premade SciMLOperators](premade_operators.md), one can specify the keyword arguments used by an operator with an `accepted_kwargs` argument (by default, none are passed).
207207

208208
In the below example, we create an operator that gleefully ignores `u`, `p`, and `t` and uses its own special scaling.
209+
209210
```@example
210211
using SciMLOperators
211212
212-
γ = ScalarOperator(0.0; update_func=(a, u, p, t; my_special_scaling) -> my_special_scaling,
213-
accepted_kwargs=(:my_special_scaling,))
213+
γ = ScalarOperator(0.0;
214+
update_func = (a, u, p, t; my_special_scaling) -> my_special_scaling,
215+
accepted_kwargs = (:my_special_scaling,))
214216
215217
# Update coefficients, then apply operator
216-
update_coefficients!(γ, nothing, nothing, nothing; my_special_scaling=7.0)
218+
update_coefficients!(γ, nothing, nothing, nothing; my_special_scaling = 7.0)
217219
@show γ * [2.0]
218220
219221
# Use operator application form

docs/src/premade_operators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SciMLOperators.AddedScalarOperator
2121
SciMLOperators.ComposedScalarOperator
2222
SciMLOperators.InvertedScalarOperator
2323
```
24+
2425
## Lazy Operator Combination
2526

2627
```@docs

docs/src/sciml.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ an extended operator interface with all of these properties, hence the
3232
`AbstractSciMLOperator` interface.
3333

3434
Some packages providing similar functionality are
35-
* [LinearMaps.jl](https://github.com/JuliaLinearAlgebra/LinearMaps.jl)
36-
* [`DiffEqOperators.jl`](https://github.com/SciML/DiffEqOperators.jl/tree/master) (deprecated)
35+
36+
- [LinearMaps.jl](https://github.com/JuliaLinearAlgebra/LinearMaps.jl)
37+
- [`DiffEqOperators.jl`](https://github.com/SciML/DiffEqOperators.jl/tree/master) (deprecated)
3738

3839
## Interoperability and extended Julia ecosystem
3940

@@ -58,10 +59,11 @@ We provide below a list of packages that make use of `SciMLOperators`.
5859
If you are using `SciMLOperators` in your work, feel free to create a PR
5960
and add your package to this list.
6061

61-
* [`SciML.ai`](https://sciml.ai/) ecosystem: `SciMLOperators` is compatible with, and utilized by every `SciML` package.
62-
* [`CalculustJL`](https://github.com/CalculustJL) packages use `SciMLOperators` to define matrix-free vector-calculus operators for solving partial differential equations.
63-
* [`CalculustCore.jl`](https://github.com/CalculustJL/CalculustCore.jl)
64-
* [`FourierSpaces.jl`](https://github.com/CalculustJL/FourierSpaces.jl)
65-
* [`NodalPolynomialSpaces.jl`](https://github.com/CalculustJL/NodalPolynomialSpaces.jl)
66-
* `SparseDiffTools.jl`
62+
- [`SciML.ai`](https://sciml.ai/) ecosystem: `SciMLOperators` is compatible with, and utilized by every `SciML` package.
6763

64+
- [`CalculustJL`](https://github.com/CalculustJL) packages use `SciMLOperators` to define matrix-free vector-calculus operators for solving partial differential equations.
65+
66+
+ [`CalculustCore.jl`](https://github.com/CalculustJL/CalculustCore.jl)
67+
+ [`FourierSpaces.jl`](https://github.com/CalculustJL/FourierSpaces.jl)
68+
+ [`NodalPolynomialSpaces.jl`](https://github.com/CalculustJL/NodalPolynomialSpaces.jl)
69+
- `SparseDiffTools.jl`

docs/src/tutorials/fftw.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,3 @@ Dx = F \ ik * F
110110
≈(Dx * u, du; atol = 1.0e-8) = true
111111
≈(mul!(copy(u), Dx, u), du; atol = 1.0e-8) = true
112112
```
113-
114-

0 commit comments

Comments
 (0)