From 7b41bc4ab5b9539b6f084934bfa88080bea2e76b Mon Sep 17 00:00:00 2001 From: janEbert Date: Thu, 24 Oct 2019 12:40:38 +0200 Subject: [PATCH] Change `gate` function to `view` instead of copy Only for vector input as copying a matrix may be more efficient due to caching. A matrix is sliced per row, meaning the view will not be aligned. --- src/layers/recurrent.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/recurrent.jl b/src/layers/recurrent.jl index f2344af8..499a21ab 100644 --- a/src/layers/recurrent.jl +++ b/src/layers/recurrent.jl @@ -1,5 +1,5 @@ gate(h, n) = (1:h) .+ h*(n-1) -gate(x::AbstractVector, h, n) = x[gate(h,n)] +gate(x::AbstractVector, h, n) = @view x[gate(h,n)] gate(x::AbstractMatrix, h, n) = x[gate(h,n),:] # Stateful recurrence