-
Notifications
You must be signed in to change notification settings - Fork 44
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
Use sinc
to fix RotationVec near zero
#272
Conversation
By converting straight from RotationVec->QuatRotation, and using an implementation that exploits `sinc` to handle θ ≈ 0, we get continuous & differentiable behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I commented two suggestions.
Codecov Report
@@ Coverage Diff @@
## master #272 +/- ##
==========================================
+ Coverage 90.42% 90.50% +0.08%
==========================================
Files 17 17
Lines 1660 1664 +4
==========================================
+ Hits 1501 1506 +5
+ Misses 159 158 -1
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
A type instability was introduced in this PR. Before this PR julia> using Rotations
julia> QuatRotation(RotationVec(0f0, 0f0, 0f0))
3×3 QuatRotation{Float32} with indices SOneTo(3)×SOneTo(3)(QuaternionF32(1.0, 0.0, 0.0, 0.0)):
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
julia> QuatRotation(RotationVec(0f0, 0f0, 2f0))
3×3 QuatRotation{Float32} with indices SOneTo(3)×SOneTo(3)(QuaternionF32(0.540302, 0.0, 0.0, 0.841471)):
-0.416147 -0.909297 0.0
0.909297 -0.416147 0.0
0.0 0.0 1.0 After this PR julia> using Rotations
julia> QuatRotation(RotationVec(0f0, 0f0, 0f0))
3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(1.0, 0.0, 0.0, 0.0)):
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
julia> QuatRotation(RotationVec(0f0, 0f0, 2f0))
3×3 QuatRotation{Float32} with indices SOneTo(3)×SOneTo(3)(QuaternionF32(0.540302, 0.0, 0.0, 0.841471)):
-0.416147 -0.909297 0.0
0.909297 -0.416147 0.0
0.0 0.0 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this PR in a few days if there are no objections.
By converting straight from RotationVec->QuatRotation,
and using an implementation that exploits
sinc
to handle θ ≈ 0,we get continuous & differentiable behavior.
Requires JuliaDiff/ForwardDiff.jl#669 before tests will pass.
What this fixes: currently, near the origin the Hessian is zero (which is wrong), because
*(::RotationVec, ::SVector{3})
expands only to linear order. But the fix is aimed at being broader than this specific case (otherwise, we could have just implemented a second-order approximation).Note: please check whether the relaxation of the
adjoint
test is reasonable, perhaps exact equality is necessary? If so I'll need to come up with a fix.