Skip to content

Commit

Permalink
in-place softmax
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Aug 22, 2017
1 parent 86e0e30 commit 6379100
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/activation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

relu(x) = max(0, x)

softmax(xs::AbstractVector) = exp.(xs) ./ sum(exp.(xs))
softmax!(out::AbstractVecOrMat, xs::AbstractVecOrMat) =
out .= exp.(xs) ./ sum(exp, xs, 1)

softmax(xs::AbstractMatrix) = exp.(xs) ./ sum(exp.(xs), 1)
softmax!(xs) = softmax!(xs, xs)

softmax(xs) = softmax!(similar(xs), xs)

0 comments on commit 6379100

Please sign in to comment.