Skip to content

Commit

Permalink
more cases of norecompile
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Aug 23, 2022
1 parent 1ae1816 commit 8a8b8cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JumpProcesses"
uuid = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
authors = ["Chris Rackauckas <[email protected]>"]
version = "9.1.1"
version = "9.1.2"

[deps]
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
Expand Down
51 changes: 45 additions & 6 deletions src/coupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,22 @@ end
function cat_problems(prob::DiffEqBase.AbstractODEProblem,
prob_control::DiffEqBase.AbstractODEProblem)
l = length(prob.u0) # add l_c = length(prob_control.u0)

if isdefined(SciMLBase, :unwrapped_f)
_f = SciMLBase.unwrapped_f(prob.f)
else
_f = prob.f
end

if isdefined(SciMLBase, :unwrapped_f)
_f_control = SciMLBase.unwrapped_f(prob_control.f)
else
_f_control = prob_c
end

new_f = function (du, u, p, t)
prob.f(@view(du[1:l]), u.u, p, t)
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
_f(@view(du[1:l]), u.u, p, t)
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
end
u0_coupled = CoupledArray(prob.u0, prob_control.u0, true)
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
Expand All @@ -33,9 +46,22 @@ function cat_problems(prob::DiscreteProblem, prob_control::DiffEqBase.AbstractOD
if !(typeof(prob.f) <: typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
end

if isdefined(SciMLBase, :unwrapped_f)
_f = SciMLBase.unwrapped_f(prob.f)
else
_f = prob.f
end

if isdefined(SciMLBase, :unwrapped_f)
_f_control = SciMLBase.unwrapped_f(prob_control.f)
else
_f_control = prob_c
end

new_f = function (du, u, p, t)
prob.f(@view(du[1:l]), u.u, p, t)
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
_f(@view(du[1:l]), u.u, p, t)
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
end
u0_coupled = CoupledArray(prob.u0, prob_control.u0, true)
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
Expand All @@ -59,9 +85,22 @@ end
function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
prob_control::DiffEqBase.AbstractODEProblem)
l = length(prob.u0)

if isdefined(SciMLBase, :unwrapped_f)
_f = SciMLBase.unwrapped_f(prob.f)
else
_f = prob.f
end

if isdefined(SciMLBase, :unwrapped_f)
_f_control = SciMLBase.unwrapped_f(prob_control.f)
else
_f_control = prob_c
end

new_f = function (du, u, p, t)
prob.f(@view(du[1:l]), u.u, p, t)
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
_f(@view(du[1:l]), u.u, p, t)
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
end
new_g = function (du, u, p, t)
prob.g(@view(du[1:l]), u.u, p, t)
Expand Down

3 comments on commit 8a8b8cb

@isaacsas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want let blocks for these like you used in the previous case?

@ChrisRackauckas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still wondering whether the split coupling needs to be removed or overhauled 😅

@isaacsas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have no idea if it really works at this point, and I doubt anyone is using it. It probably should get improved at some point anyways…

Please sign in to comment.