Skip to content

Commit c5c3dde

Browse files
Merge pull request #3579 from DhairyaLGandhi/dg/copymtk
Copy `MTKParameters` fields only if not empty
2 parents b849190 + e8b1d8e commit c5c3dde

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/systems/parameter_buffer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ function Base.copy(p::MTKParameters)
319319
initials = copy(p.initials)
320320
discrete = Tuple(eltype(buf) <: Real ? copy(buf) : copy.(buf) for buf in p.discrete)
321321
constant = Tuple(eltype(buf) <: Real ? copy(buf) : copy.(buf) for buf in p.constant)
322-
nonnumeric = copy.(p.nonnumeric)
323-
caches = copy.(p.caches)
322+
nonnumeric = isempty(p.nonnumeric) ? p.nonnumeric : copy.(p.nonnumeric)
323+
caches = isempty(p.caches) ? p.caches : copy.(p.caches)
324324
return MTKParameters(
325325
tunable,
326326
initials,

test/mtkparameters.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ ivs = Dict(c => 3a, d => 4, e => [5.0, 6.0, 7.0],
1818

1919
ps = MTKParameters(sys, ivs)
2020
@test_nowarn copy(ps)
21+
ps_copy = copy(ps)
22+
ps_field_equals = map(fieldnames(typeof(ps))) do f
23+
getfield(ps, f) == getfield(ps_copy, f)
24+
end
25+
@test all(ps_field_equals)
2126
# dependent initialization, also using defaults
2227
@test getp(sys, a)(ps) == getp(sys, b)(ps) == getp(sys, c)(ps) == 0.0
2328
@test getp(sys, d)(ps) isa Int

0 commit comments

Comments
 (0)