From 82261b5bb7e6783d6a273c8e7803c4fbb28a3dd8 Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Tue, 10 Sep 2019 00:54:49 -0700 Subject: [PATCH] make activations zygote friendly --- src/layers/basic.jl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/layers/basic.jl b/src/layers/basic.jl index 13d56472..fd187d8c 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -45,17 +45,15 @@ end # it might be replaced in the future for better performance # see issue https://github.com/FluxML/Flux.jl/issues/702 # Johnny Chen -- @johnnychen94 +# only slightly changed to better handle interaction with Zygote @dsweber2 """ activations(c::Chain, input) Calculate the forward results of each layers in Chain `c` with `input` as model input. """ function activations(c::Chain, input) - rst = [] - for l in c - x = get(rst, length(rst), input) - push!(rst, l(x)) - end - return rst + buffed = accumulate!((x,y)->y(x), Zygote.Buffer([], length(c)), + [l for l in c], dims=1, init=input) + return copy(buffed) end