@@ -803,6 +803,61 @@ function remake(prob::NonlinearLeastSquaresProblem; f = missing, u0 = missing, p
803803 return prob
804804end
805805
806+ function scc_update_subproblems (probs:: Vector , newu0, newp, parameters_alias)
807+ offset = Ref (0 )
808+ return map (probs) do subprob
809+ # N should be inferred if `prob` is type-stable and `subprob.u0 isa StaticArray`
810+ N = length (state_values (subprob))
811+ if ArrayInterface. ismutable (newu0)
812+ _u0 = newu0[(offset[] + 1 ): (offset[] + N)]
813+ else
814+ _u0 = StaticArraysCore. similar_type (
815+ newu0, StaticArraysCore. Size (N))(newu0[(offset[] + 1 ): (offset[] + N)])
816+ end
817+ subprob = if parameters_alias === Val (true )
818+ remake (subprob; u0 = _u0, p = newp)
819+ else
820+ remake (subprob; u0 = _u0)
821+ end
822+ offset[] += length (state_values (subprob))
823+ return subprob
824+ end
825+ end
826+
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
850+ 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
859+ end
860+
806861"""
807862 remake(prob::SCCNonlinearProblem; u0 = missing, p = missing, probs = missing,
808863 parameters_alias = prob.parameters_alias, sys = missing, explicitfuns! = missing)
@@ -818,7 +873,10 @@ override the values in `probs`. `sys` is the index provider for the full system.
818873function remake (prob:: SCCNonlinearProblem ; u0 = missing , p = missing , probs = missing ,
819874 parameters_alias = prob. parameters_alias, f = missing , sys = missing ,
820875 interpret_symbolicmap = true , use_defaults = false , explicitfuns! = missing )
821- if p != = missing && ! parameters_alias && probs === missing
876+ if parameters_alias isa Bool
877+ parameters_alias = Val (parameters_alias)
878+ end
879+ if p != = missing && parameters_alias === Val (false ) && probs === missing
822880 throw (ArgumentError (" `parameters_alias` is `false` for the given `SCCNonlinearProblem`. Please provide the subproblems using the keyword `probs` with the parameters updated appropriately in each." ))
823881 end
824882 newu0, newp = updated_u0_p (prob, u0, p; interpret_symbolicmap, use_defaults)
@@ -831,28 +889,14 @@ function remake(prob::SCCNonlinearProblem; u0 = missing, p = missing, probs = mi
831889 if sys === missing
832890 sys = prob. f. sys
833891 end
834- offset = 0
835- if u0 != = missing || p != = missing && parameters_alias
836- probs = map (probs) do subprob
837- subprob = if parameters_alias
838- remake (subprob;
839- u0 = newu0[(offset + 1 ): (offset + length (state_values (subprob)))],
840- p = newp)
841- else
842- remake (subprob;
843- u0 = newu0[(offset + 1 ): (offset + length (state_values (subprob)))])
844- end
845- offset += length (state_values (subprob))
846- return subprob
847- end
892+ if u0 != = missing || p != = missing && parameters_alias === Val (true )
893+ probs = scc_update_subproblems (probs, newu0, newp, parameters_alias)
848894 end
849895 f = coalesce (f, prob. f)
850896 f = remake (f; sys)
851- props = getproperties (f)
852- props = @delete props. f
853897
854- return SCCNonlinearProblem (
855- probs, explicitfuns!, newp, parameters_alias; props ... )
898+ return SCCNonlinearProblem {typeof(probs), typeof(explicitfuns!), typeof(f), typeof(newp)} (
899+ probs, explicitfuns!, f, newp, parameters_alias)
856900end
857901
858902function varmap_has_var (varmap, var)
0 commit comments