Skip to content

Commit 71023dc

Browse files
fix: fix memory aliasing with array discrete parameters
1 parent 3a837ca commit 71023dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/systems/parameter_buffer.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,17 @@ function SciMLBase.create_parameter_timeseries_collection(
840840
return ParameterTimeseriesCollection(Tuple(buffers), copy(ps))
841841
end
842842

843+
@inline __get_blocks(tsidx::Int) = ()
844+
@inline function __get_blocks(tsidx::Int, buffer::BlockedArray, buffers...)
845+
(buffer[Block(tsidx)], __get_blocks(tsidx, buffers...)...)
846+
end
847+
@inline function __get_blocks(tsidx::Int, buffer::BlockedArray{<:AbstractArray}, buffers...)
848+
(copy.(buffer[Block(tsidx)]), __get_blocks(tsidx, buffers...)...)
849+
end
850+
843851
function SciMLBase.get_saveable_values(
844852
sys::AbstractSystem, ps::MTKParameters, timeseries_idx)
845-
return NestedGetIndex(Tuple(buffer[Block(timeseries_idx)] for buffer in ps.discrete))
853+
return NestedGetIndex(__get_blocks(timeseries_idx, ps.discrete...))
846854
end
847855

848856
function save_callback_discretes!(integ::SciMLBase.DEIntegrator, callback)

0 commit comments

Comments
 (0)