-
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
Add option to skip renormalization of AngleAxis
and Quat
#37
Conversation
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.
Looks really useful to me.
src/angleaxis_types.jl
Outdated
norm = sqrt(x*x + y*y + z*z) | ||
# Not sure what to do with theta?? Should it become theta * norm ? | ||
new(θ, x/norm, y/norm, z/norm) | ||
@inline function AngleAxis{T}(θ, x, y, z, ::Val{Normalize} = Val{true}()) where {T, Normalize} |
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.
Does this actually need to be a Val
or can you just pass a normal Bool
? I'd expect constant prop to optimize away the branches anyway at the LLVM level. The only time I'd expect this to make any difference is if the two sides of the branch could result in different types for T
. But I'm not sure it's very useful to allow T == Int
, say, in any case.
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.
Good call; just tested: LLVM is indeed able to optimize that branch away. I'll update the PR.
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.
Done.
3301bec
to
ccfa89f
Compare
ccfa89f
to
45d001e
Compare
This is a good idea. I'm impressed that LLVM can optimize the branch away optimally with a |
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.
Looks good to me.
Nice documentation, by the way :) |
Thanks! Re:
The scalar type of the BTW, both before and after this PR, the current constructor setup can result in moderately unexpected behavior for some sqrt(x::Real) = sqrt(float(x)) which, combined with the conversion from Quat{Rational{Int64}}(3774540503726565//4503599627370496, 3774540503726565//9007199254740992, 1258180167908855//4503599627370496, 3774540503726565//18014398509481984) Again, I don't think this matters too much. |
Agreed, though I'm not sure our constructors make a huge amount of sense as they are right now. For example, I think the @inline Quat(w::T, x::T, y::T, z::T) where {T} = Quat{typeof((zero(T) + one(T))/one(T))}(w, x, y, z)
@inline Quat(w, x, y, z) = Quat(promote(w, x, y, z)...) Which would correctly promote integers, rather than just producing an error. Hmm. Does this affect the choice of Val-or-not? |
By the way, feel free to merge, unless you want to explore the consequences of "fixing" the constructors. |
OK, merged, since the constructor stuff is more or less orthogonal to this change ( |
I've noticed that the renormalization in
AngleAxis
now accounts for a nontrivial percentage of time spent in my kinematics code, even though I know for sure that the axis I pass in is a unit vector. In addition, there could be scalar types for which normalization is not desired (see JuliaRobotics/RigidBodyDynamics.jl#87). This PR adds the option to skip the normalization in the constructor.I checked that the generated code is the same as it was before for calls to
Quat(w, x, y, z)
andAngleAxis(theta, x, y, z)
. This required an@inline
annotation for the inner constructors.