Skip to content

Commit 3679069

Browse files
fix: fix remake_buffer with a Tuple buffer and Dict{Any, Any} varmap
1 parent d25fd41 commit 3679069

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/remake.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ end
7777

7878
function remake_buffer(sys, oldbuffer::Tuple, idxs, vals)
7979
wrap = TupleRemakeWrapper(oldbuffer)
80-
setu(sys, idxs)(wrap, vals)
80+
for (idx, val) in zip(idxs, vals)
81+
setu(sys, idx)(wrap, val)
82+
end
8183
return wrap.t
8284
end
8385

8486
@deprecate remake_buffer(sys, oldbuffer, vals::Dict) remake_buffer(
8587
sys, oldbuffer, keys(vals), values(vals))
8688
@deprecate remake_buffer(sys, oldbuffer::Tuple, vals::Dict) remake_buffer(
87-
sys, oldbuffer, collect(keys(vals)), collect(values(vals)))
89+
sys, oldbuffer, keys(vals), values(vals))

test/remake_test.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ for (buf, newbuf, idxs, vals) in [
2323
# skip non-parameters
2424
([1, 2, 3], [2.0, 3.0, 3.0], [:a, :b, :(a + b)], [2.0, 3.0, 5.0])
2525
]
26+
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
27+
for varmap in [Dict(idxs .=> vals), Dict{Any, Any}(idxs .=> vals)]
28+
_newbuf = remake_buffer(sys, buf, keys(varmap), values(varmap))
29+
@test _newbuf != buf
30+
@test newbuf == _newbuf
31+
@test typeof(newbuf) == typeof(_newbuf)
32+
end
2633
for arrType in [Vector, SVector{3}, MVector{3}, SizedVector{3}]
2734
buf = arrType(buf)
2835
newbuf = arrType(newbuf)
@@ -31,7 +38,6 @@ for (buf, newbuf, idxs, vals) in [
3138
@test _newbuf != buf # should not alias
3239
@test newbuf == _newbuf # test values
3340
@test typeof(newbuf) == typeof(_newbuf) # ensure appropriate type
34-
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
3541
end
3642
end
3743

@@ -55,8 +61,13 @@ for (buf, newbuf, idxs, vals) in [
5561
# skip non-variables
5662
([1, 2, 3], [2.0, 3.0, 3.0], [:x, :y, :(x + y)], [2.0, 3.0, 5.0])
5763
]
64+
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
65+
for varmap in [Dict(idxs .=> vals), Dict{Any, Any}(idxs .=> vals)]
66+
_newbuf = remake_buffer(sys, buf, keys(varmap), values(varmap))
67+
@test newbuf == _newbuf
68+
@test typeof(newbuf) == typeof(_newbuf)
69+
end
5870
_newbuf = remake_buffer(sys, buf, idxs, vals)
5971
@test newbuf == _newbuf # test values
6072
@test typeof(newbuf) == typeof(_newbuf) # ensure appropriate type
61-
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
6273
end

0 commit comments

Comments
 (0)