Skip to content

Commit 5ba3d32

Browse files
fix: fix type-stability of remake(::SCCNonlinearProblem) on julia@10
1 parent 559d141 commit 5ba3d32

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/remake.jl

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -824,26 +824,38 @@ function scc_update_subproblems(probs::Vector, newu0, newp, parameters_alias)
824824
end
825825
end
826826

827-
function scc_update_subproblems(probs::Tuple, newu0, newp, parameters_alias)
828-
offset = Ref(0)
829-
return ntuple(Val(length(probs))) do i
830-
subprob = probs[i]
831-
# N should be inferred if `prob` is type-stable and `subprob.u0 isa StaticArray`
832-
N = length(state_values(subprob))
833-
if ArrayInterface.ismutable(newu0)
834-
_u0 = newu0[(offset[] + 1):(offset[] + N)]
835-
else
836-
_u0 = StaticArraysCore.similar_type(
837-
newu0, StaticArraysCore.Size(N))(newu0[(offset[] + 1):(offset[] + N)])
838-
end
839-
subprob = if parameters_alias === Val(true)
840-
remake(subprob; u0 = _u0, p = newp)
841-
else
842-
remake(subprob; u0 = _u0)
843-
end
844-
offset[] += N
845-
return subprob
827+
@generated function scc_update_subproblems(probs::Tuple, newu0, newp, parameters_alias)
828+
function get_expr(i::Int)
829+
subprob_name = Symbol(:subprob, i)
830+
quote
831+
$subprob_name = probs[$i]
832+
# N should be inferred if `prob` is type-stable and `subprob.u0 isa StaticArray`
833+
N = length(state_values($subprob_name))
834+
if ArrayInterface.ismutable(newu0)
835+
_u0 = newu0[(offset + 1):(offset + N)]
836+
else
837+
_u0 = StaticArraysCore.similar_type(
838+
newu0, StaticArraysCore.Size(N))(newu0[(offset + 1):(offset + N)])
839+
end
840+
$subprob_name = if parameters_alias === Val(true)
841+
remake($subprob_name; u0 = _u0, p = newp)
842+
else
843+
remake($subprob_name; u0 = _u0)
844+
end
845+
offset += N
846+
end, subprob_name
847+
end
848+
expr = quote
849+
offset = 0
846850
end
851+
subprob_names = []
852+
for i in 1:fieldcount(probs)
853+
subexpr, spname = get_expr(i)
854+
push!(expr.args, subexpr)
855+
push!(subprob_names, spname)
856+
end
857+
push!(expr.args, Expr(:tuple, subprob_names...))
858+
return expr
847859
end
848860

849861
"""
@@ -882,11 +894,9 @@ function remake(prob::SCCNonlinearProblem; u0 = missing, p = missing, probs = mi
882894
end
883895
f = coalesce(f, prob.f)
884896
f = remake(f; sys)
885-
props = getproperties(f)
886-
props = @delete props.f
887897

888-
return SCCNonlinearProblem(
889-
probs, explicitfuns!, newp, parameters_alias; props...)
898+
return SCCNonlinearProblem{typeof(probs), typeof(explicitfuns!), typeof(f), typeof(newp)}(
899+
probs, explicitfuns!, f, newp, parameters_alias)
890900
end
891901

892902
function varmap_has_var(varmap, var)

0 commit comments

Comments
 (0)