Skip to content

Commit a9ca3e7

Browse files
fix: remove unnecessary copies in late_binding_update_u0_p
1 parent 6950927 commit a9ca3e7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/systems/nonlinear/initializesystem.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,20 +664,26 @@ function SciMLBase.late_binding_update_u0_p(
664664
newp = p === missing ? copy(newp) : newp
665665
initials, repack, alias = SciMLStructures.canonicalize(
666666
SciMLStructures.Initials(), newp)
667-
initials = DiffEqBase.promote_u0(initials, newu0, t0)
668-
newp = repack(initials)
667+
if eltype(initials) != eltype(newu0)
668+
initials = DiffEqBase.promote_u0(initials, newu0, t0)
669+
newp = repack(initials)
670+
end
669671
setp(sys, Initial.(unknowns(sys)))(newp, newu0)
670672
return newu0, newp
671673
end
672674

673675
newp = p === missing ? copy(newp) : newp
674676
newu0 = DiffEqBase.promote_u0(newu0, newp, t0)
675677
tunables, repack, alias = SciMLStructures.canonicalize(SciMLStructures.Tunable(), newp)
676-
tunables = DiffEqBase.promote_u0(tunables, newu0, t0)
677-
newp = repack(tunables)
678+
if eltype(tunables) != eltype(newu0)
679+
tunables = DiffEqBase.promote_u0(tunables, newu0, t0)
680+
newp = repack(tunables)
681+
end
678682
initials, repack, alias = SciMLStructures.canonicalize(SciMLStructures.Initials(), newp)
679-
initials = DiffEqBase.promote_u0(initials, newu0, t0)
680-
newp = repack(initials)
683+
if eltype(initials) != eltype(newu0)
684+
initials = DiffEqBase.promote_u0(initials, newu0, t0)
685+
newp = repack(initials)
686+
end
681687

682688
allsyms = all_symbols(sys)
683689
for (k, v) in u0

0 commit comments

Comments
 (0)