Skip to content

Commit 058a25b

Browse files
committed
use 5-arg copyto
1 parent e38170d commit 058a25b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/destructure.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,18 @@ end
152152
function _rebuild!(x, off, flat::AbstractVector, len = length(flat); walk = _Trainable_biwalk(), kw...)
153153
len == length(flat) || throw(DimensionMismatch("Rebuild expected a vector of length $len, got $(length(flat))"))
154154
fmap(x, off; exclude = isnumeric, walk, kw...) do y, o
155-
copyto!(y, _getat(y, o, flat, view))
155+
# copyto!(y, _getat_view(y, o, flat))
156+
copyto!(y, 1, flat, o+1, length(y))
156157
end
157158
x
158159
end
159160

160-
_getat(y::Number, o::Int, flat::AbstractVector, _...) = ProjectTo(y)(flat[o + 1])
161-
_getat(y::AbstractArray, o::Int, flat::AbstractVector, get=getindex) =
162-
ProjectTo(y)(reshape(get(flat, o .+ (1:length(y))), axes(y))) # ProjectTo is just correcting eltypes
161+
_getat(y::Number, o::Int, flat::AbstractVector) = ProjectTo(y)(flat[o + 1])
162+
_getat(y::AbstractArray, o::Int, flat::AbstractVector) =
163+
ProjectTo(y)(reshape(flat[o .+ (1:length(y))], axes(y))) # ProjectTo is just correcting eltypes
164+
165+
# _getat_view(y::AbstractArray, o::Int, flat::AbstractVector) =
166+
# view(flat, o .+ (1:length(y)))
163167

164168
struct _Trainable_biwalk <: AbstractWalk end
165169

0 commit comments

Comments
 (0)