-
Notifications
You must be signed in to change notification settings - Fork 43
Add support for higher dimensional rotation #219
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 support for higher dimensional rotation #219
Conversation
The CI log says: Testing isrotation: Error During Test at /home/runner/work/Rotations.jl/Rotations.jl/test/rotation_tests.jl:439
Test threw exception
Expression: isrotation(I(1))
MethodError: objects of type UniformScaling{Bool} are not callable
Stacktrace:
[1] macro expansion at /home/runner/work/Rotations.jl/Rotations.jl/test/rotation_tests.jl:439 [inlined]
[2] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Test/src/Test.jl:1083 [inlined]
[3] macro expansion at /home/runner/work/Rotations.jl/Rotations.jl/test/rotation_tests.jl:407 [inlined]
[4] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Test/src/Test.jl:1083 [inlined]
[5] top-level scope at /home/runner/work/Rotations.jl/Rotations.jl/test/rotation_tests.jl:89 Like JuliaArrays/StaticArrays.jl#985, we can drop support under Julia v1.6. |
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
==========================================
+ Coverage 88.14% 88.56% +0.41%
==========================================
Files 15 16 +1
Lines 1603 1626 +23
==========================================
+ Hits 1413 1440 +27
+ Misses 190 186 -4
Continue to review full report at Codecov.
|
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.
This looks great to me. Should we have isrotationgenerator(r, tol)
implemented and use a small relative tolerance by default as in the algorithm for Base.≈
?
b4e6a7a
to
f6f9ffa
Compare
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.
LGTM
if indsm != indsn | ||
return false | ||
end | ||
for i in indsn, j in i:last(indsn) |
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:last(indsn)
Oh that's subtle. But I think it's correct given the indsm != indsn
check.
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.
Should we replace the line with this?
for i in indsm, j in i:last(indsn)
In the next line, we have the following script, so it seems okay to assume that both indices have the same axes.
if r[i,j] != -r[j,i]
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.
Oh! now that you mention it, I'd somehow read that as i:last(indsm)
already...
I think it's fine/good to leave this alone and not deviate from ishermitian()
more than necessary.
Thanks for the review! I have added a TODO list in the description. |
I was misunderstanding the rotation angle of highter dimensional rotation, and I have reverted the |
71115de
to
3e08e9e
Compare
I have added documentation, and I think this is ready to merge. |
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.
Still looks good to me. I noticed a few minor things which could be cleaned up.
Codecov noticed a few new lines without tests - would be good to fix those too.
src/rand.jl
Outdated
@@ -0,0 +1,70 @@ | |||
function Random.rand(rng::AbstractRNG, ::Random.SamplerType{R}) where R <: Union{<:Rotation{2},<:RotMatrix{2}} | |||
# Union{<:Rotation{2},<:RotMatrix{2}} seems able to be replaced with Rotation{2}, | |||
# but it avoids the method for general dimensional RotMatrix. |
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 don't quite understand this comment
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.
We can produce random RotMatrix{2}
instance in two ways:
- Generate random angle in [0,2π] and create
RotMatrix{2}
instance. - Generate random matrix from
randn(2,2)
and convert it toRotMatrix{2}
withnearest_rotation
.
The first one is much effective in terms of performance, and the last one can be generalized to high dimensional rotations.
The type R <: Union{<:Rotation{2},<:RotMatrix{2}}
in the first line has been changed from the original R <: Rotation{2}
to be calculated with uniform distribution on [0,2π] when calling rand(::RotMatrix{2})
. (Note that RotMatrix{2}<:Rotation{2}
, and Union{<:Rotation{2},<:RotMatrix{2}}
is almost equivalent to Rotation{2}
)
I was trying to comment on the reason for this change, but maybe I could not make my English understood... 😵💫
Or, is there a better to make rand(RotMatrix{2})
select a method based on a uniform distribution of [0,2π] without using Union
?
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.
Oh, I think I see. So the point here is that including <:RotMatrix{2}
makes this method of rand
more specific than the method for general RotMatrix
?
In that case I'd word this as something like
# We use the awkward Union{<:Rotation{2},<:RotMatrix{2}} here rather than `Rotation{2}`
# to make this efficient 2D method more specific than the method for general `RotMatrix`
Your English is quite good! It's hard to express this tricky technical point succinctly.
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.
Thanks for the suggestion! I've updated the comments that way.
Co-authored-by: Chris Foster <[email protected]>
Co-authored-by: Chris Foster <[email protected]>
This PR fixes #215.
RotMatrix{N}
constructorRotMatrixGenerator{N}
constructorexp
functionRotMatrixGenerator{N}
toRotMatrix{N}
log
functionRotMatrix{N}
toRotMatrixGenerator{N}
isrotationgenerator
functionrotation_angle
rand
method