From 6475f6a43eba8feab5f34a7dc2cf0f86d1d7c0fc Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Wed, 11 Sep 2019 17:36:37 -0700 Subject: [PATCH] recursive way of doing activations --- src/layers/basic.jl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/layers/basic.jl b/src/layers/basic.jl index c3783567..b92bc919 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -50,16 +50,17 @@ end Calculate the forward results of each layers in Chain `c` with `input` as model input. """ function activations(c::Chain, input) - res = Zygote.Buffer([], length(c)) - if length(c) > 0 - res[1] = c[1](input) - for (i,l) in enumerate(c[2:end]) - res[i+1] = l(res[i]) - end - end - return copy(res) + extraChain(c.layers, input) end +function extraChain(fs::Tuple, x) + res = first(fs)(x) + return (res, extraChain(Base.tail(fs), res)...) +end + +extraChain(::Tuple{}, x) = [] + + """ Dense(in::Integer, out::Integer, σ = identity)