Skip to content

Commit

Permalink
Use view for RNN gate slice extraction
Browse files Browse the repository at this point in the history
This was originally passed over in #907, but I don't find that argument particularly compelling as the return value is only ever used once. Any negative impact on caching is going to happen anyhow during the slice materialization, so we might as well just let the subsequent fused broadcasts handle said materialization for us while reducing allocations.
  • Loading branch information
ToucheSir committed Nov 6, 2021
1 parent ea26f45 commit 85e3054
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/layers/recurrent.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

gate(h, n) = (1:h) .+ h*(n-1)
gate(x::AbstractVector, h, n) = @view x[gate(h,n)]
gate(x::AbstractMatrix, h, n) = x[gate(h,n),:]
gate(x::AbstractMatrix, h, n) = @view x[gate(h,n),:]

# Stateful recurrence

Expand Down

0 comments on commit 85e3054

Please sign in to comment.