JuliaGeometry / JuliaGeometry/Rotations.jl

NaNs when using ForwardDiff with RodriguesVec

Open
#96 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

differentiation
Dominant language
Julia
Stars
188
Forks
45
PR merge metrics
No merged PRs in 30d

Description

For example:

julia> using ForwardDiff, Rotations

julia> ForwardDiff.derivative(0) do x
           rotation_angle(RodriguesVec(x, 0, 0))
       end
NaN

This comes out of the way the rotation angle is computed, which involves sqrt(rv.sx * rv.sx + ...), and which fails because the derivative of sqrt at 0 is inf (from above).

However, there is a correct answer for this derivative (it's 0), so I wonder if we can make the computation a bit more robust. For example, the generic LinearAlgebra.norm does the right thing:

julia> ForwardDiff.derivative(0.0) do x
           rv = RodriguesVec(x, 0, 0)
           norm([rv.sx, rv.sy, rv.sz])
       end
0.0

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

Reproduce the ForwardDiff.derivative example using rotation_angle(RodriguesVec(x, 0, 0)) and inspect the rotation_angle computation that takes the square root of the RodriguesVec components. Compare its behavior with LinearAlgebra.norm at zero. Done means the derivative at zero returns 0 rather than NaN while preserving the expected rotation angle.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.