128128function split_into_buffers (raw:: AbstractArray , buf; recurse = true )
129129 idx = 1
130130 function _helper (buf_v; recurse = true )
131- if eltype (buf_v) isa AbstractArray && recurse
131+ if eltype (buf_v) <: AbstractArray && recurse
132132 return _helper .(buf_v; recurse = false )
133133 else
134134 res = reshape (raw[idx: (idx + length (buf_v) - 1 )], size (buf_v))
@@ -139,6 +139,19 @@ function split_into_buffers(raw::AbstractArray, buf; recurse = true)
139139 return Tuple (_helper (buf_v; recurse) for buf_v in buf)
140140end
141141
142+ function update_tuple_of_buffers (raw:: AbstractArray , buf)
143+ idx = 1
144+ function _helper (buf_v)
145+ if eltype (buf_v) <: AbstractArray
146+ _helper .(buf_v)
147+ else
148+ copyto! (buf_v, view (raw, idx: (idx + length (buf_v) - 1 )))
149+ idx += length (buf_v)
150+ end
151+ end
152+ _helper .(buf)
153+ end
154+
142155SciMLStructures. isscimlstructure (:: MTKParameters ) = true
143156
144157SciMLStructures. ismutablescimlstructure (:: MTKParameters ) = true
@@ -151,7 +164,7 @@ for (Portion, field) in [(SciMLStructures.Tunable, :tunable)
151164 repack = let as_vector = as_vector, p = p
152165 function (new_val)
153166 if new_val != = as_vector
154- p. $ field = split_into_buffers (new_val, p.$ field)
167+ update_tuple_of_buffers (new_val, p.$ field)
155168 end
156169 if p. dependent_update_iip != = nothing
157170 p. dependent_update_iip (ArrayPartition (p. dependent), p... )
0 commit comments