JuliaDiff / JuliaDiff/ForwardDiff.jl

norm() on a zero vector with non-zero partials gives nan value for v1.3.1+

Open
#794 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
1k
Forks
160
PR merge metrics
No merged PRs in 30d

Description

I noticed a change in behavior when upgrading from v1.3.0 to v1.3.1+. It seems that when taking the norm of a zero vector of duals, sometimes a NaN value for the norm gets produced. Interestingly, using LinearAlgebra does this but taking the norm manually bypasses the issue.

using ForwardDiff
using StaticArrays
using LinearAlgebra

v = SA[ForwardDiff.Dual(0.0, 1.0), ForwardDiff.Dual(0.0, 1.0), ForwardDiff.Dual(0.0, 1.0)]
norm_v = norm(v)
norm_v_manual = sqrt(v[1]^2 + v[2]^2 + v[3]^2)
println(norm_v)
println(norm_v_manual)

In v1.3.0, norm_v and norm_v_manual are the same, but in v1.3.1+, norm_v becomes Dual(NaN,NaN)

What's the reason for this inconsistency? And which result is intended to be correct?

Happy to do more testing!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied Julia reproducer with ForwardDiff, StaticArrays, and LinearAlgebra under v1.3.0 and v1.3.1+. Trace the LinearAlgebra norm path for ForwardDiff.Dual and compare it with the manual sqrt expression; done means explaining the discrepancy and identifying which zero-vector result is intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.