-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AD norm is NaN at origin #191
Comments
Not really a solution because the "correct" answer should be julia> using LinearAlgebra, Tensors
julia> h,g,v = Tensors.hessian(norm,zero(Tensor{2,2}),:all); println.((h,g,v));
[NaN NaN; NaN NaN;;; NaN NaN; NaN NaN;;;; NaN NaN; NaN NaN;;; NaN NaN; NaN NaN]
[NaN NaN; NaN NaN]
0.0
julia> function dnorm_dx(x::AbstractTensor)
n = norm(x)
dn = (n == zero(n)) ? zero(x) : x / n
return n, dn
end
julia> LinearAlgebra.norm(x::Tensor{2,<:Any,<:Tensors.Dual}) = Tensors._propagate_gradient(dnorm_dx, x)
julia> h,g,v = Tensors.hessian(norm,zero(Tensor{2,2}),:all); println.((h,g,v));
[0.0 0.0; 0.0 0.0;;; 0.0 0.0; 0.0 0.0;;;; 0.0 0.0; 0.0 0.0;;; 0.0 0.0; 0.0 0.0]
[0.0 0.0; 0.0 0.0]
0.0
julia> h,g,v = Tensors.hessian(norm,rand(Tensor{2,2}),:all);
julia> norm(g)
0.9999999999999999 (See docs in #181 ) |
Imo, ForwardDiff should switch to Nan-safe mode by default. |
I tried running the benchmarks with and without NaN-safe mode, but couldn't figure out how to show the results from the Tensors.jl ad benchmarks nicely. |
Not really specific to
Tensors.jl
, but maybe it's good to document it here as well. I ran into the following issue yesterdayBasically a duplicate of JuliaDiff/ChainRules.jl#576 and JuliaDiff/ForwardDiff.jl#547 just at a different repo. You can close it if you think its too redundant.
The text was updated successfully, but these errors were encountered: