@@ -41,52 +41,61 @@ julia> Pkg.add("SciMLOperators")
4141Let ` 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
4549N = 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
4961M = MatrixOperator(rand(N, N))
5062D = DiagonalOperator(rand(N))
51- F = FunctionOperator (f, zeros (N), zeros (N))
63+ F = FunctionOperator(f, zeros(N), zeros(N); u, p, t )
5264```
5365
5466Then, the following codes just work.
5567
56- ``` julia
68+ ``` @example operator_algebra
5769L1 = 2M + 3F + LinearAlgebra.I + rand(N, N)
5870L2 = D * F * M'
5971L3 = kron(M, D, F)
60- L4 = M \ D
72+ L4 = lu(M) \ D
6173L5 = [M; D]' * [M F; F D] * [F; D]
6274```
6375
6476Each ` 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
8493L2 = cache_operator(L2, u)
8594L4 = 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
0 commit comments