Skip to content

Commit

Permalink
Merge pull request #66 from SciML/as/partial-remake
Browse files Browse the repository at this point in the history
feat: support partial updates with remake_buffer
  • Loading branch information
ChrisRackauckas authored Apr 12, 2024
2 parents 063783b + 267909c commit 6a4e7e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ returned buffer should be of the same type (ignoring type-parameters) as `oldbuf
This method is already implemented for
`remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)` and supports static arrays
as well.
as well. It is also implemented for `oldbuffer::Tuple`.
"""
function remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)
# similar when used with an `MArray` and nonconcrete eltype returns a
Expand All @@ -23,6 +23,7 @@ function remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)
end

newbuffer = similar(oldbuffer, elT)
copyto!(newbuffer, oldbuffer)
setu(sys, collect(keys(vals)))(newbuffer, elT.(values(vals)))
else
mutbuffer = remake_buffer(sys, collect(oldbuffer), vals)
Expand Down
8 changes: 4 additions & 4 deletions test/remake_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ for (buf, newbuf, newvals) in [
# standard operation
([1.0, 2.0, 3.0], [2.0, 3.0, 4.0], Dict(:x => 2.0, :y => 3.0, :z => 4.0)),
# buffer type "demotion"
([1.0, 2.0, 3.0], [2, 3, 4], Dict(:x => 2, :y => 3, :z => 4)),
([1.0, 2.0, 3.0], [2, 2, 3], Dict(:x => 2)),
# buffer type promotion
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:x => 2.0, :y => 3.0, :z => 4.0)),
([1, 2, 3], [2.0, 2.0, 3.0], Dict(:x => 2.0)),
# value type promotion
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:x => 2, :y => 3.0, :z => 4.0)),
# standard operation
([1.0, 2.0, 3.0], [2.0, 3.0, 4.0], Dict(:a => 2.0, :b => 3.0, :c => 4.0)),
# buffer type "demotion"
([1.0, 2.0, 3.0], [2, 3, 4], Dict(:a => 2, :b => 3, :c => 4)),
([1.0, 2.0, 3.0], [2, 2, 3], Dict(:a => 2)),
# buffer type promotion
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:a => 2.0, :b => 3.0, :c => 4.0)),
([1, 2, 3], [2.0, 2.0, 3.0], Dict(:a => 2.0)),
# value type promotion
([1, 2, 3], [2, 3.0, 4.0], Dict(:a => 2, :b => 3.0, :c => 4.0))
]
Expand Down

0 comments on commit 6a4e7e9

Please sign in to comment.