From d59745986ad41be68fa768a1d955aa8274897c4e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 31 Aug 2019 22:00:48 -0700 Subject: [PATCH 1/2] Add `solve!` and default `solve` definition --- README.md | 2 +- src/CommonSolve.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 152bc13..300e741 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ This holds the common `solve` command. The rules are that you must dispatch on one of your own types. That's it. No pirates. -Oh and there's an `init` as well. +Oh and there're `init` and `solve!` as well. diff --git a/src/CommonSolve.jl b/src/CommonSolve.jl index c2e3a80..93f5edf 100644 --- a/src/CommonSolve.jl +++ b/src/CommonSolve.jl @@ -1,6 +1,7 @@ module CommonSolve -function solve end +solve(args...; kwargs...) = solve!(init(args...; kwargs...)) +function solve! end function init end end # module From d51c2ef5aa28db818a3807c9fb760e52d2cf7b2e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 31 Aug 2019 22:01:27 -0700 Subject: [PATCH 2/2] Add General recommendation --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 300e741..2e774c1 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,29 @@ This holds the common `solve` command. The rules are that you must dispatch on one of your own types. That's it. No pirates. Oh and there're `init` and `solve!` as well. + +## General recommendation + +`solve` function has the default definition + +```julia +solve(args...; kwargs...) = solve!(init(args...; kwargs...)) +``` + +So, we recommend defining + +```julia +init(::ProblemType, args...; kwargs...) :: SolverType +solve!(::SolverType) :: SolutionType +``` + +where `ProblemType`, `SolverType`, and `SolutionType` are the types defined in +your package. + +To avoid method ambiguity, the first argument of `solve`, `solve!`, and `init` +_must_ be dispatched on the type defined in your package. For example, do +_not_ define a method such as + +```julia +init(::AbstractVector, ::AlgorithmType) +```