Skip to content

Commit

Permalink
fix: fix remake_buffer with a Tuple buffer and Dict{Any, Any} v…
Browse files Browse the repository at this point in the history
…armap
  • Loading branch information
AayushSabharwal committed Sep 5, 2024
1 parent d25fd41 commit 3679069
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ end

function remake_buffer(sys, oldbuffer::Tuple, idxs, vals)
wrap = TupleRemakeWrapper(oldbuffer)
setu(sys, idxs)(wrap, vals)
for (idx, val) in zip(idxs, vals)
setu(sys, idx)(wrap, val)
end
return wrap.t
end

@deprecate remake_buffer(sys, oldbuffer, vals::Dict) remake_buffer(
sys, oldbuffer, keys(vals), values(vals))
@deprecate remake_buffer(sys, oldbuffer::Tuple, vals::Dict) remake_buffer(
sys, oldbuffer, collect(keys(vals)), collect(values(vals)))
sys, oldbuffer, keys(vals), values(vals))
15 changes: 13 additions & 2 deletions test/remake_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ for (buf, newbuf, idxs, vals) in [
# skip non-parameters
([1, 2, 3], [2.0, 3.0, 3.0], [:a, :b, :(a + b)], [2.0, 3.0, 5.0])
]
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
for varmap in [Dict(idxs .=> vals), Dict{Any, Any}(idxs .=> vals)]
_newbuf = remake_buffer(sys, buf, keys(varmap), values(varmap))
@test _newbuf != buf
@test newbuf == _newbuf
@test typeof(newbuf) == typeof(_newbuf)
end
for arrType in [Vector, SVector{3}, MVector{3}, SizedVector{3}]
buf = arrType(buf)
newbuf = arrType(newbuf)
Expand All @@ -31,7 +38,6 @@ for (buf, newbuf, idxs, vals) in [
@test _newbuf != buf # should not alias
@test newbuf == _newbuf # test values
@test typeof(newbuf) == typeof(_newbuf) # ensure appropriate type
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
end
end

Expand All @@ -55,8 +61,13 @@ for (buf, newbuf, idxs, vals) in [
# skip non-variables
([1, 2, 3], [2.0, 3.0, 3.0], [:x, :y, :(x + y)], [2.0, 3.0, 5.0])
]
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
for varmap in [Dict(idxs .=> vals), Dict{Any, Any}(idxs .=> vals)]
_newbuf = remake_buffer(sys, buf, keys(varmap), values(varmap))
@test newbuf == _newbuf
@test typeof(newbuf) == typeof(_newbuf)
end
_newbuf = remake_buffer(sys, buf, idxs, vals)
@test newbuf == _newbuf # test values
@test typeof(newbuf) == typeof(_newbuf) # ensure appropriate type
@test_deprecated remake_buffer(sys, buf, Dict(idxs .=> vals))
end

0 comments on commit 3679069

Please sign in to comment.