From 95b8b393f3a8b61211115339c5cd426e481b42aa Mon Sep 17 00:00:00 2001 From: Julian Samaroo Date: Sun, 12 Jan 2025 13:23:49 -0600 Subject: [PATCH] docs: Fixes for solver developing information --- docs/src/advanced/developing.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/src/advanced/developing.md b/docs/src/advanced/developing.md index c15c8b70e..b2476c638 100644 --- a/docs/src/advanced/developing.md +++ b/docs/src/advanced/developing.md @@ -15,18 +15,20 @@ Let's create a new wrapper for a simple LU-factorization which uses only the basic machinery. A simplified version is: ```julia -struct MyLUFactorization{P} <: SciMLBase.AbstractLinearAlgorithm end +struct MyLUFactorization{P} <: LinearSolve.SciMLLinearSolveAlgorithm end -function init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol, - verbose) +function LinearSolve.init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol, reltol, + verbose::Bool, assump::LinearSolve.OperatorAssumptions) lu!(convert(AbstractMatrix, A)) end -function SciMLBase.solve!(cache::LinearCache, alg::MyLUFactorization; kwargs...) +function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::MyLUFactorization; kwargs...) if cache.isfresh + A = cache.A A = convert(AbstractMatrix, A) fact = lu!(A) - cache = set_cacheval(cache, fact) + cache.cacheval = fact + cache.isfresh = false end y = ldiv!(cache.u, cache.cacheval, cache.b) SciMLBase.build_linear_solution(alg, y, nothing, cache) @@ -39,7 +41,7 @@ need to cache their own things, and so there's one value `cacheval` that is for the algorithms to modify. The function: ```julia -init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose) +init_cacheval(alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose, assump) ``` is what is called at `init` time to create the first `cacheval`. Note that this @@ -51,13 +53,13 @@ LU-factorization to get an `LU{T, Matrix{T}}` which it puts into the `cacheval` so it is typed for future use. After the `init_cacheval`, the only thing left to do is to define -`SciMLBase.solve(cache::LinearCache, alg::MyLUFactorization)`. Many algorithms +`SciMLBase.solve!(cache::LinearCache, alg::MyLUFactorization)`. Many algorithms may use a lazy matrix-free representation of the operator `A`. Thus, if the algorithm requires a concrete matrix, like LU-factorization does, the algorithm should `convert(AbstractMatrix,cache.A)`. The flag `cache.isfresh` states whether `A` has changed since the last `solve`. Since we only need to factorize when `A` is new, the factorization part of the algorithm is done in a `if cache.isfresh`. -`cache = set_cacheval(cache, fact)` puts the new factorization into the cache, +`cache.cacheval = fact; cache.isfresh = false` puts the new factorization into the cache, so it's updated for future solves. Then `y = ldiv!(cache.u, cache.cacheval, cache.b)` performs the solve and a linear solution is returned via `SciMLBase.build_linear_solution(alg,y,nothing,cache)`.