Skip to content

Commit

Permalink
gradient for norm
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Apr 29, 2019
1 parent 2170544 commit 6c66c22
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ end
end
end

function _forward(cx::Context, ::typeof(norm), x::AbstractArray, p::Real = 2)
fallback = (x, p) -> sum(abs.(x).^p .+ eps(0f0))^(1/p) # avoid d(sqrt(x))/dx == Inf at 0
_forward(cx, fallback, x, p)
end

# LinAlg Matrix Types
# ===================

Expand Down

0 comments on commit 6c66c22

Please sign in to comment.