Skip to content

Commit

Permalink
Merge pull request #3 from tkf/bang
Browse files Browse the repository at this point in the history
Add `solve!` and default `solve` definition
  • Loading branch information
ChrisRackauckas authored Sep 1, 2019
2 parents 37ab315 + d51c2ef commit 3b4db33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,30 @@
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.

## 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)
```
3 changes: 2 additions & 1 deletion src/CommonSolve.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module CommonSolve

function solve end
solve(args...; kwargs...) = solve!(init(args...; kwargs...))
function solve! end
function init end

end # module

0 comments on commit 3b4db33

Please sign in to comment.