Skip to content

Commit

Permalink
fix: ignore symbols in remake_buffer which aren't variables or para…
Browse files Browse the repository at this point in the history
…meters
  • Loading branch information
AayushSabharwal committed Sep 2, 2024
1 parent e8c5c23 commit c0d8cd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function remake_buffer(sys, oldbuffer::AbstractArray, idxs, vals)
newbuffer = similar(oldbuffer, elT)
copyto!(newbuffer, oldbuffer)
for (k, v) in zip(idxs, vals)
is_variable(sys, k) || is_parameter(sys, k) || continue
if v isa AbstractArray
v = elT.(v)
else
Expand Down
8 changes: 6 additions & 2 deletions test/remake_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ for (buf, newbuf, idxs, vals) in [
# buffer type promotion
([1, 2, 3], [2.0, 2.0, 3.0], [:a], [2.0]),
# value type promotion
([1, 2, 3], [2, 3.0, 4.0], [:a, :b, :c], Real[2, 3.0, 4.0])
([1, 2, 3], [2, 3.0, 4.0], [:a, :b, :c], Real[2, 3.0, 4.0]),
# skip non-parameters
([1, 2, 3], [2.0, 3.0, 3.0], [:a, :b, :(a + b)], [2.0, 3.0, 5.0])
]
for arrType in [Vector, SVector{3}, MVector{3}, SizedVector{3}]
buf = arrType(buf)
Expand Down Expand Up @@ -49,7 +51,9 @@ for (buf, newbuf, idxs, vals) in [
# buffer type promotion
((1, 2, 3), (2.0, 3.0, 4.0), [:x, :y, :z], [2.0, 3.0, 4.0]),
# value type promotion
((1, 2, 3), (2, 3.0, 4.0), [:x, :y, :z], Real[2, 3.0, 4.0])
((1, 2, 3), (2, 3.0, 4.0), [:x, :y, :z], Real[2, 3.0, 4.0]),
# skip non-variables
([1, 2, 3], [2.0, 3.0, 3.0], [:x, :y, :(x + y)], [2.0, 3.0, 5.0])
]
_newbuf = remake_buffer(sys, buf, idxs, vals)
@test newbuf == _newbuf # test values
Expand Down

0 comments on commit c0d8cd1

Please sign in to comment.