Flux.jl/src/jit/inplace.jl

12 lines
255 B
Julia
Raw Normal View History

2018-02-08 20:49:04 +00:00
mutable struct Cached{F,A}
f::F
buffer::A
end
function (c::Cached)(args...)
sh = shape(c.f, shape(args)...)
bytes(sh) > length(c.buffer) && (c.buffer = similar(c.buffer, bytes(sh)))
y = restructure(sh, c.buffer)
inplace!(c.f, y, args...)
end