Skip to content

Commit 6a4e7e9

Browse files
Merge pull request #66 from SciML/as/partial-remake
feat: support partial updates with remake_buffer
2 parents 063783b + 267909c commit 6a4e7e9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/remake.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ returned buffer should be of the same type (ignoring type-parameters) as `oldbuf
1111
1212
This method is already implemented for
1313
`remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)` and supports static arrays
14-
as well.
14+
as well. It is also implemented for `oldbuffer::Tuple`.
1515
"""
1616
function remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)
1717
# similar when used with an `MArray` and nonconcrete eltype returns a
@@ -23,6 +23,7 @@ function remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)
2323
end
2424

2525
newbuffer = similar(oldbuffer, elT)
26+
copyto!(newbuffer, oldbuffer)
2627
setu(sys, collect(keys(vals)))(newbuffer, elT.(values(vals)))
2728
else
2829
mutbuffer = remake_buffer(sys, collect(oldbuffer), vals)

test/remake_test.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ for (buf, newbuf, newvals) in [
77
# standard operation
88
([1.0, 2.0, 3.0], [2.0, 3.0, 4.0], Dict(:x => 2.0, :y => 3.0, :z => 4.0)),
99
# buffer type "demotion"
10-
([1.0, 2.0, 3.0], [2, 3, 4], Dict(:x => 2, :y => 3, :z => 4)),
10+
([1.0, 2.0, 3.0], [2, 2, 3], Dict(:x => 2)),
1111
# buffer type promotion
12-
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:x => 2.0, :y => 3.0, :z => 4.0)),
12+
([1, 2, 3], [2.0, 2.0, 3.0], Dict(:x => 2.0)),
1313
# value type promotion
1414
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:x => 2, :y => 3.0, :z => 4.0)),
1515
# standard operation
1616
([1.0, 2.0, 3.0], [2.0, 3.0, 4.0], Dict(:a => 2.0, :b => 3.0, :c => 4.0)),
1717
# buffer type "demotion"
18-
([1.0, 2.0, 3.0], [2, 3, 4], Dict(:a => 2, :b => 3, :c => 4)),
18+
([1.0, 2.0, 3.0], [2, 2, 3], Dict(:a => 2)),
1919
# buffer type promotion
20-
([1, 2, 3], [2.0, 3.0, 4.0], Dict(:a => 2.0, :b => 3.0, :c => 4.0)),
20+
([1, 2, 3], [2.0, 2.0, 3.0], Dict(:a => 2.0)),
2121
# value type promotion
2222
([1, 2, 3], [2, 3.0, 4.0], Dict(:a => 2, :b => 3.0, :c => 4.0))
2323
]

0 commit comments

Comments
 (0)