Skip to content

Commit 392ef5e

Browse files
Merge pull request #47 from korsbo/function_overload
Function overload
2 parents 3c615e5 + ee9f608 commit 392ef5e

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
julia 0.6
2-
DiffEqJump 1.0.0
2+
DiffEqJump 4.2.0
33
DiffEqBase 3.4.0
44
Compat 0.17.0
55
DataStructures 0.4.6

src/DiffEqBiological.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include("maketype.jl")
1717
include("problem.jl")
1818

1919
export @reaction_network, @reaction_func
20-
export ODEProblem, SDEProblem, JumpProblem, SteadyStateProblem
20+
export SDEProblem, JumpProblem, SteadyStateProblem
2121

2222
Reaction(args...) = error("""
2323
The old Reaction DSL is deprecated for a new

src/problem.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
### ODEProblem ###
2-
DiffEqBase.ODEProblem(rn::AbstractReactionNetwork, args...; kwargs...) =
3-
ODEProblem(rn.f, args...; kwargs...)
4-
51
### SDEProblem ###
6-
DiffEqBase.SDEProblem(rn::AbstractReactionNetwork, args...; kwargs...) =
7-
SDEProblem(rn.f,rn.g, args...;noise_rate_prototype=rn.p_matrix, kwargs...)
2+
DiffEqBase.SDEProblem(rn::AbstractReactionNetwork, u0::Union{AbstractArray, Number}, args...; kwargs...) =
3+
SDEProblem(rn, rn.g, u0, args...;noise_rate_prototype=rn.p_matrix, kwargs...)
84

95
### JumpProblem ###
106
function DiffEqJump.JumpProblem(prob,aggregator::Direct,rn::AbstractReactionNetwork; kwargs...)

src/reaction_network.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ function coordinate(name, ex::Expr, p, scale_noise)
110110
push!(exprs,typeex)
111111
push!(exprs,constructorex)
112112

113+
## Overload the type so that it can act as a function.
114+
overloadex = :(((f::$name))(du, u, p, t::Number) = f.f(du, u, p, t)) |> esc
115+
push!(exprs,overloadex)
116+
117+
## Add a method which allocates the `du` and returns it instead of being inplace
118+
overloadex = :(((f::$name))(u,p,t::Number) = (du=similar(u); f(du,u,p,t); du)) |> esc
119+
push!(exprs,overloadex)
120+
113121
# export type constructor
114122
def_const_ex = :(($name)()) |> esc
115123
push!(exprs,def_const_ex)

test/REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
OrdinaryDiffEq
22
StochasticDiffEq
3-
SteadyStateDiffEq
3+
SteadyStateDiffEq 0.4.0

test/solver_test.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ sol1 = solve(prob1,Tsit5())
4141
prob2 = ODEProblem(equi_model,[100.],(0.,200.))
4242
sol2 = solve(prob2,Tsit5())
4343
@test 1.5*sol1[end][1] < sol2[end][1]
44+
45+
@test sol1.prob.f isa AbstractReactionNetwork

0 commit comments

Comments
 (0)