Skip to content

Commit 3b4db33

Browse files
Merge pull request #3 from tkf/bang
Add `solve!` and default `solve` definition
2 parents 37ab315 + d51c2ef commit 3b4db33

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,30 @@
33
This holds the common `solve` command. The rules are that you must dispatch
44
on one of your own types. That's it. No pirates.
55

6-
Oh and there's an `init` as well.
6+
Oh and there're `init` and `solve!` as well.
7+
8+
## General recommendation
9+
10+
`solve` function has the default definition
11+
12+
```julia
13+
solve(args...; kwargs...) = solve!(init(args...; kwargs...))
14+
```
15+
16+
So, we recommend defining
17+
18+
```julia
19+
init(::ProblemType, args...; kwargs...) :: SolverType
20+
solve!(::SolverType) :: SolutionType
21+
```
22+
23+
where `ProblemType`, `SolverType`, and `SolutionType` are the types defined in
24+
your package.
25+
26+
To avoid method ambiguity, the first argument of `solve`, `solve!`, and `init`
27+
_must_ be dispatched on the type defined in your package. For example, do
28+
_not_ define a method such as
29+
30+
```julia
31+
init(::AbstractVector, ::AlgorithmType)
32+
```

src/CommonSolve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module CommonSolve
22

3-
function solve end
3+
solve(args...; kwargs...) = solve!(init(args...; kwargs...))
4+
function solve! end
45
function init end
56

67
end # module

0 commit comments

Comments
 (0)