Skip to content

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

Merged
merged 32 commits into from
Feb 17, 2022

Conversation

hyrodium
Copy link
Collaborator

@hyrodium hyrodium commented Jan 16, 2022

This PR fixes #215.

  • RotMatrix{N} constructor
  • RotMatrixGenerator{N} constructor
  • exp function RotMatrixGenerator{N} to RotMatrix{N}
  • log function RotMatrix{N} to RotMatrixGenerator{N}
  • isrotationgenerator function
  • rotation_angle
  • rand method
  • documentation

@hyrodium
Copy link
Collaborator Author

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
Copy link

codecov bot commented Jan 28, 2022

Codecov Report

Merging #219 (9294916) into master (4f76c5a) will increase coverage by 0.41%.
The diff coverage is 98.82%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/euler_types.jl 92.25% <ø> (-0.18%) ⬇️
src/mrps.jl 34.93% <ø> (-0.88%) ⬇️
src/rodrigues_params.jl 98.64% <ø> (-0.04%) ⬇️
src/unitquaternion.jl 96.36% <ø> (-0.04%) ⬇️
src/logexp.jl 93.33% <93.33%> (+11.51%) ⬆️
src/core_types.jl 94.81% <100.00%> (+0.65%) ⬆️
src/rand.jl 100.00% <100.00%> (ø)
src/rotation_generator.jl 96.35% <100.00%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f76c5a...9294916. Read the comment docs.

Copy link
Member

@c42f c42f left a 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.≈?

@hyrodium hyrodium force-pushed the feature/higher_diemsions branch from b4e6a7a to f6f9ffa Compare February 3, 2022 14:47
Copy link
Member

@c42f c42f left a 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)
Copy link
Member

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.

Copy link
Collaborator Author

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]

Copy link
Member

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.

@hyrodium
Copy link
Collaborator Author

hyrodium commented Feb 4, 2022

Thanks for the review! I have added a TODO list in the description.

@hyrodium
Copy link
Collaborator Author

I was misunderstanding the rotation angle of highter dimensional rotation, and I have reverted the rotation_angle for highter dimensional rotation.
I thought a rotation have one rotation angle, but that was incorrect; in general, a n-dimensional rotation has n÷2 rotation angles.
See https://cs.brynmawr.edu/~dxu/206-2550-2.pdf for more information.

@hyrodium hyrodium force-pushed the feature/higher_diemsions branch from 71115de to 3e08e9e Compare February 12, 2022 09:22
@hyrodium hyrodium marked this pull request as ready for review February 13, 2022 14:06
@hyrodium
Copy link
Collaborator Author

hyrodium commented Feb 13, 2022

I have added documentation, and I think this is ready to merge.

Copy link
Member

@c42f c42f left a 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.
Copy link
Member

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

Copy link
Collaborator Author

@hyrodium hyrodium Feb 15, 2022

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 to RotMatrix{2} with nearest_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?

Copy link
Member

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.

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for higher dimensional rotation
2 participants