Skip to content

Commit 0d2e37c

Browse files
Fix tensor application to slides and fix README
1 parent 7bd5d8e commit 0d2e37c

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,52 +41,61 @@ julia> Pkg.add("SciMLOperators")
4141
Let `M`, `D`, `F` be matrix-based, diagonal-matrix-based, and function-based
4242
`SciMLOperators` respectively.
4343

44-
```julia
44+
Let `M`, `D`, `F` be matrix-based, diagonal-matrix-based, and function-based
45+
`SciMLOperators` respectively.
46+
47+
```@example operator_algebra
48+
using SciMLOperators, LinearAlgebra
4549
N = 4
46-
f(u, p, t) = u .* u
47-
f(v, u, p, t) = v .= u .* u
50+
function f(v, u, p, t)
51+
u .* v
52+
end
53+
function f(w, v, u, p, t)
54+
w .= u .* v
55+
end
56+
57+
u = rand(4)
58+
p = nothing # parameter struct
59+
t = 0.0 # time
4860
4961
M = MatrixOperator(rand(N, N))
5062
D = DiagonalOperator(rand(N))
51-
F = FunctionOperator(f, zeros(N), zeros(N))
63+
F = FunctionOperator(f, zeros(N), zeros(N); u, p, t)
5264
```
5365

5466
Then, the following codes just work.
5567

56-
```julia
68+
```@example operator_algebra
5769
L1 = 2M + 3F + LinearAlgebra.I + rand(N, N)
5870
L2 = D * F * M'
5971
L3 = kron(M, D, F)
60-
L4 = M \ D
72+
L4 = lu(M) \ D
6173
L5 = [M; D]' * [M F; F D] * [F; D]
6274
```
6375

6476
Each `L#` can be applied to `AbstractVector`s of appropriate sizes:
6577

66-
```julia
67-
p = nothing # parameter struct
68-
t = 0.0 # time
69-
70-
u = rand(N)
71-
v = L1(u, p, t) # == L1 * u
78+
```@example operator_algebra
79+
v = rand(N)
80+
w = L1(v, u, p, t) # == L1 * v
7281
73-
u_kron = rand(N^3)
74-
v_kron = L3(u_kron, p, t) # == L3 * u_kron
82+
v_kron = rand(N^3)
83+
w_kron = L3(v_kron, u, p, t) # == L3 * v_kron
7584
```
7685

77-
For mutating operator evaluations, call `cache_operator` to generate
78-
in-place cache so the operation is nonallocating.
86+
For mutating operator evaluations, call `cache_operator` to generate an
87+
in-place cache, so the operation is nonallocating.
7988

80-
```julia
89+
```@example operator_algebra
8190
α, β = rand(2)
8291
8392
# allocate cache
8493
L2 = cache_operator(L2, u)
8594
L4 = cache_operator(L4, u)
8695
8796
# allocation-free evaluation
88-
L2(v, u, p, t) # == mul!(v, L2, u)
89-
L4(v, u, p, t, α, β) # == mul!(v, L4, u, α, β)
97+
L2(w, v, u, p, t) # == mul!(w, L2, v)
98+
L4(w, v, u, p, t, α, β) # == mul!(w, L4, v, α, β)
9099
```
91100

92101
## Roadmap

docs/src/tutorials/operator_algebras.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## [Demonstration of Operator Algebras and Kron](@id operator_algebras)
22

33
Let `M`, `D`, `F` be matrix-based, diagonal-matrix-based, and function-based
4-
`SciMLOperators` respectively.
4+
`SciMLOperators` respectively. Here are some examples of composing operators
5+
in order to build more complex objects and using their operations.
56

67
```@example operator_algebra
78
using SciMLOperators, LinearAlgebra
@@ -55,15 +56,4 @@ L4 = cache_operator(L4, u)
5556
# allocation-free evaluation
5657
L2(w, v, u, p, t) # == mul!(w, L2, v)
5758
L4(w, v, u, p, t, α, β) # == mul!(w, L4, v, α, β)
58-
```
59-
60-
The calling signature `L(v, u, p, t)`, for out-of-place evaluations, is
61-
equivalent to `L * v`, and the in-place evaluation `L(w, v, u, p, t, args...)`
62-
is equivalent to `LinearAlgebra.mul!(w, L, v, args...)`, where the arguments
63-
`u, p, t` are passed to `L` to update its state. More details are provided
64-
in the operator update section below.
65-
66-
The `(v, u, p, t)` calling signature is standardized over the `SciML`
67-
ecosystem and is flexible enough to support use cases such as time-evolution
68-
in ODEs, as well as sensitivity computation with respect to the parameter
69-
object `p`.
59+
```

src/tensor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function Base.:*(L::TensorProductOperator, v::AbstractVecOrMat)
172172
k = size(v, 2)
173173

174174
U = reshape(v, (ni, no * k))
175-
C = inner * U
175+
C = stack([inner * _v for _v in eachcol(U)])
176176

177177
V = outer_mul(L, v, C)
178178

0 commit comments

Comments
 (0)