From 19cf3919b98a7e8f086d95ea124124112a7531d4 Mon Sep 17 00:00:00 2001 From: Mateusz Baran Date: Mon, 11 Sep 2023 14:56:49 +0200 Subject: [PATCH] more tests and some fixes --- src/groups/special_euclidean.jl | 26 +++++++++--------- src/manifolds/CholeskySpace.jl | 2 +- src/manifolds/Flag.jl | 6 ++-- src/manifolds/FlagOrthogonal.jl | 2 +- src/manifolds/Orthogonal.jl | 2 +- src/manifolds/Sphere.jl | 4 +-- src/manifolds/Symmetric.jl | 4 +-- src/manifolds/SymmetricPositiveDefinite.jl | 2 +- src/manifolds/Unitary.jl | 3 +- test/manifolds/euclidean.jl | 32 ++++++++++++++++++++++ test/manifolds/flag.jl | 7 +++++ test/manifolds/sphere.jl | 6 ++++ test/manifolds/unitary_matrices.jl | 4 +++ 13 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/groups/special_euclidean.jl b/src/groups/special_euclidean.jl index ff4438c6cc..fad35614b1 100644 --- a/src/groups/special_euclidean.jl +++ b/src/groups/special_euclidean.jl @@ -357,7 +357,7 @@ exponential (see [`exp_lie`](@ref)). exp_lie(::SpecialEuclidean, ::Any) @doc raw""" - exp_lie(G::SpecialEuclidean{2}, X) + exp_lie(G::SpecialEuclidean{TypeParameter{Tuple{2}}}, X) Compute the group exponential of $X = (b, Ω) ∈ 𝔰𝔢(2)$, where $b ∈ 𝔱(2)$ and $Ω ∈ 𝔰𝔬(2)$: @@ -374,10 +374,10 @@ U(θ) = \frac{\sin θ}{θ} I_2 + \frac{1 - \cos θ}{θ^2} Ω, and $θ = \frac{1}{\sqrt{2}} \lVert Ω \rVert_e$ (see [`norm`](@ref norm(M::Rotations, p, X))) is the angle of the rotation. """ -exp_lie(::SpecialEuclidean{2}, ::Any) +exp_lie(::SpecialEuclidean{TypeParameter{Tuple{2}}}, ::Any) @doc raw""" - exp_lie(G::SpecialEuclidean{3}, X) + exp_lie(G::SpecialEuclidean{TypeParameter{Tuple{3}}}, X) Compute the group exponential of $X = (b, Ω) ∈ 𝔰𝔢(3)$, where $b ∈ 𝔱(3)$ and $Ω ∈ 𝔰𝔬(3)$: @@ -394,7 +394,7 @@ U(θ) = I_3 + \frac{1 - \cos θ}{θ^2} Ω + \frac{θ - \sin θ}{θ^3} Ω^2, and $θ = \frac{1}{\sqrt{2}} \lVert Ω \rVert_e$ (see [`norm`](@ref norm(M::Rotations, p, X))) is the angle of the rotation. """ -exp_lie(::SpecialEuclidean{3}, ::Any) +exp_lie(::SpecialEuclidean{TypeParameter{Tuple{3}}}, ::Any) function exp_lie!(G::SpecialEuclidean, q, X) Xmat = screw_matrix(G, X) @@ -403,7 +403,7 @@ function exp_lie!(G::SpecialEuclidean, q, X) _padpoint!(G, q) return q end -function exp_lie!(G::SpecialEuclidean{2}, q, X) +function exp_lie!(G::SpecialEuclidean{TypeParameter{Tuple{2}}}, q, X) SO2 = submanifold(G, 2) b, Ω = submanifold_components(G, X) t, R = submanifold_components(G, q) @@ -432,7 +432,7 @@ function exp_lie!(G::SpecialEuclidean{2}, q, X) end return q end -function exp_lie!(G::SpecialEuclidean{3}, q, X) +function exp_lie!(G::SpecialEuclidean{TypeParameter{Tuple{3}}}, q, X) SO3 = submanifold(G, 2) b, Ω = submanifold_components(G, X) t, R = submanifold_components(G, q) @@ -461,7 +461,7 @@ function exp_lie!(G::SpecialEuclidean{3}, q, X) end @doc raw""" - log_lie(G::SpecialEuclidean{n}, p) where {n} + log_lie(G::SpecialEuclidean, p) Compute the group logarithm of $p = (t, R) ∈ \mathrm{SE}(n)$, where $t ∈ \mathrm{T}(n)$ and $R ∈ \mathrm{SO}(n)$: @@ -478,7 +478,7 @@ In the [`affine_matrix`](@ref) representation, the group logarithm is the matrix log_lie(::SpecialEuclidean, ::Any) @doc raw""" - log_lie(G::SpecialEuclidean{2}, p) + log_lie(G::SpecialEuclidean{TypeParameter{Tuple{2}}}, p) Compute the group logarithm of $p = (t, R) ∈ \mathrm{SE}(2)$, where $t ∈ \mathrm{T}(2)$ and $R ∈ \mathrm{SO}(2)$: @@ -496,10 +496,10 @@ U(θ) = \frac{\sin θ}{θ} I_2 + \frac{1 - \cos θ}{θ^2} Ω, and $θ = \frac{1}{\sqrt{2}} \lVert Ω \rVert_e$ (see [`norm`](@ref norm(M::Rotations, p, X))) is the angle of the rotation. """ -log_lie(::SpecialEuclidean{2}, ::Any) +log_lie(::SpecialEuclidean{TypeParameter{Tuple{2}}}, ::Any) @doc raw""" - log_lie(G::SpecialEuclidean{3}, p) + log_lie(G::SpecialEuclidean{TypeParameter{Tuple{3}}}, p) Compute the group logarithm of $p = (t, R) ∈ \mathrm{SE}(3)$, where $t ∈ \mathrm{T}(3)$ and $R ∈ \mathrm{SO}(3)$: @@ -517,7 +517,7 @@ U(θ) = I_3 + \frac{1 - \cos θ}{θ^2} Ω + \frac{θ - \sin θ}{θ^3} Ω^2, and $θ = \frac{1}{\sqrt{2}} \lVert Ω \rVert_e$ (see [`norm`](@ref norm(M::Rotations, p, X))) is the angle of the rotation. """ -log_lie(::SpecialEuclidean{3}, ::Any) +log_lie(::SpecialEuclidean{TypeParameter{Tuple{3}}}, ::Any) function _log_lie!(G::SpecialEuclidean, X, q) qmat = affine_matrix(G, q) @@ -526,7 +526,7 @@ function _log_lie!(G::SpecialEuclidean, X, q) _padvector!(G, X) return X end -function _log_lie!(G::SpecialEuclidean{2}, X, q) +function _log_lie!(G::SpecialEuclidean{TypeParameter{Tuple{2}}}, X, q) SO2 = submanifold(G, 2) b, Ω = submanifold_components(G, X) t, R = submanifold_components(G, q) @@ -544,7 +544,7 @@ function _log_lie!(G::SpecialEuclidean{2}, X, q) end return X end -function _log_lie!(G::SpecialEuclidean{3}, X, q) +function _log_lie!(G::SpecialEuclidean{TypeParameter{Tuple{3}}}, X, q) b, Ω = submanifold_components(G, X) t, R = submanifold_components(G, q) @assert size(Ω) == (3, 3) diff --git a/src/manifolds/CholeskySpace.jl b/src/manifolds/CholeskySpace.jl index 1c713aceaf..6755ab5c7a 100644 --- a/src/manifolds/CholeskySpace.jl +++ b/src/manifolds/CholeskySpace.jl @@ -110,7 +110,7 @@ function exp!(::CholeskySpace, q, p, X) return q end -get_n(::CholeskySpace{TypeParameter{N}}) where {N} = N +get_n(::CholeskySpace{TypeParameter{Tuple{N}}}) where {N} = N get_n(M::CholeskySpace{Tuple{Int}}) = get_parameter(M.size)[1] @doc raw""" diff --git a/src/manifolds/Flag.jl b/src/manifolds/Flag.jl index 717450c38b..afa9971566 100644 --- a/src/manifolds/Flag.jl +++ b/src/manifolds/Flag.jl @@ -105,11 +105,11 @@ Get the embedding of the [`Flag`](@ref) manifold `M`, i.e. the [`Stiefel`](@ref) function get_embedding(M::Flag{Tuple{Int},dp1}) where {dp1} return Stiefel(M.size[1], M.subspace_dimensions[dp1 - 1]) end -function get_embedding(M::Flag{TypeParameter{N},dp1}) where {N,dp1} +function get_embedding(M::Flag{TypeParameter{Tuple{N}},dp1}) where {N,dp1} return Stiefel(N, M.subspace_dimensions[dp1 - 1]; parameter=:type) end -get_n(::Flag{TypeParameter{N}}) where {N} = N +get_n(::Flag{TypeParameter{Tuple{N}}}) where {N} = N get_n(M::Flag{Tuple{Int}}) = get_parameter(M.size)[1] @doc raw""" @@ -148,7 +148,7 @@ function manifold_dimension(M::Flag{<:Any,dp1}) where {dp1} return dim end -function Base.show(io::IO, M::Flag{TypeParameter{N}}) where {N} +function Base.show(io::IO, M::Flag{TypeParameter{Tuple{N}}}) where {N} print(io, "Flag($(N)") for d_i in M.subspace_dimensions.x[1:(end - 1)] print(io, ", $d_i") diff --git a/src/manifolds/FlagOrthogonal.jl b/src/manifolds/FlagOrthogonal.jl index f1de3f89b3..8795933c73 100644 --- a/src/manifolds/FlagOrthogonal.jl +++ b/src/manifolds/FlagOrthogonal.jl @@ -59,7 +59,7 @@ end Get embedding of [`Flag`](@ref) manifold `M`, i.e. the manifold [`OrthogonalMatrices`](@ref). """ -function get_embedding(::Flag{TypeParameter{N}}, p::OrthogonalPoint) where {N} +function get_embedding(::Flag{TypeParameter{Tuple{N}}}, p::OrthogonalPoint) where {N} return OrthogonalMatrices(N; parameter=:type) end get_embedding(M::Flag{Tuple{Int}}, p::OrthogonalPoint) = OrthogonalMatrices(M.size[1]) diff --git a/src/manifolds/Orthogonal.jl b/src/manifolds/Orthogonal.jl index ba4360ed91..b5e1b24c0c 100644 --- a/src/manifolds/Orthogonal.jl +++ b/src/manifolds/Orthogonal.jl @@ -36,7 +36,7 @@ function Random.rand!( return pX end -function Base.show(io::IO, ::OrthogonalMatrices{TypeParameter{n}}) where {n} +function Base.show(io::IO, ::OrthogonalMatrices{TypeParameter{Tuple{n}}}) where {n} return print(io, "OrthogonalMatrices($(n); parameter=:type)") end function Base.show(io::IO, M::OrthogonalMatrices{Tuple{Int}}) diff --git a/src/manifolds/Sphere.jl b/src/manifolds/Sphere.jl index bb3bca0001..46e4d68e4d 100644 --- a/src/manifolds/Sphere.jl +++ b/src/manifolds/Sphere.jl @@ -504,10 +504,10 @@ function Base.show(io::IO, M::Sphere{Tuple{Int},𝔽}) where {𝔽} n = get_n(M) return print(io, "Sphere($(n), $(𝔽))") end -function Base.show(io::IO, ::ArraySphere{TypeParameter{Tuple{n}},𝔽}) where {n,𝔽} +function Base.show(io::IO, ::ArraySphere{TypeParameter{tn},𝔽}) where {tn,𝔽} return print( io, - "ArraySphere($(join(n.parameters, ", ")); field = $(𝔽), parameter=:type)", + "ArraySphere($(join(tn.parameters, ", ")); field = $(𝔽), parameter=:type)", ) end function Base.show(io::IO, M::ArraySphere{<:Tuple,𝔽}) where {𝔽} diff --git a/src/manifolds/Symmetric.jl b/src/manifolds/Symmetric.jl index 47a171ba94..902948ec03 100644 --- a/src/manifolds/Symmetric.jl +++ b/src/manifolds/Symmetric.jl @@ -128,7 +128,7 @@ function get_coordinates_orthonormal!( return Y end -function get_embedding(::SymmetricMatrices{TypeParameter{N},𝔽}) where {N,𝔽} +function get_embedding(::SymmetricMatrices{TypeParameter{Tuple{N}},𝔽}) where {N,𝔽} return Euclidean(N, N; field=𝔽, parameter=:type) end function get_embedding(M::SymmetricMatrices{Tuple{Int},𝔽}) where {𝔽} @@ -166,7 +166,7 @@ function get_vector_orthonormal!(M::SymmetricMatrices{<:Any,ℂ}, Y, p, X, ::Com end ## unify within bases later. -get_n(::SymmetricMatrices{TypeParameter{n}}) where {n} = n +get_n(::SymmetricMatrices{TypeParameter{Tuple{n}}}) where {n} = n get_n(M::SymmetricMatrices{Tuple{Int}}) = get_parameter(M.size)[1] """ diff --git a/src/manifolds/SymmetricPositiveDefinite.jl b/src/manifolds/SymmetricPositiveDefinite.jl index d70b1d9282..e0c922e31a 100644 --- a/src/manifolds/SymmetricPositiveDefinite.jl +++ b/src/manifolds/SymmetricPositiveDefinite.jl @@ -232,7 +232,7 @@ function get_embedding(M::SymmetricPositiveDefinite) return Euclidean(representation_size(M)...; field=ℝ) end -get_n(::SymmetricPositiveDefinite{TypeParameter{N}}) where {N} = N +get_n(::SymmetricPositiveDefinite{TypeParameter{Tuple{N}}}) where {N} = N get_n(M::SymmetricPositiveDefinite{Tuple{Int}}) = get_parameter(M.size)[1] @doc raw""" diff --git a/src/manifolds/Unitary.jl b/src/manifolds/Unitary.jl index 07352edab1..bb5867b201 100644 --- a/src/manifolds/Unitary.jl +++ b/src/manifolds/Unitary.jl @@ -93,7 +93,7 @@ function manifold_dimension(M::UnitaryMatrices{<:Any,ℂ}) return n^2 end @doc raw""" - manifold_dimension(M::UnitaryMatrices{n,ℍ}) + manifold_dimension(M::UnitaryMatrices{<:Any,ℍ}) Return the dimension of the manifold unitary matrices. ```math @@ -183,4 +183,3 @@ function Weingarten!(::UnitaryMatrices, Y, p, X, V) end zero_vector(::UnitaryMatrices{TypeParameter{Tuple{1}},ℍ}, p) = zero(p) -zero_vector(::UnitaryMatrices{1,ℍ}, p) = zero(p) diff --git a/test/manifolds/euclidean.jl b/test/manifolds/euclidean.jl index e2daf17cdb..99c3ddecdf 100644 --- a/test/manifolds/euclidean.jl +++ b/test/manifolds/euclidean.jl @@ -395,4 +395,36 @@ using FiniteDifferences X = zeros(3) @test volume_density(E, p, X) == 1.0 end + + @testset "static parameter" begin + Ms = Euclidean(1; parameter=:type) + M0s = Euclidean(; parameter=:type) + + @test distance(Ms, 2.0, 4.0) == 2.0 + @test distance(M0s, 2.0, 4.0) == 2.0 + @test log(M0s, 2.0, 4.0) == 2.0 + @test manifold_dimension(M0s) == 1 + @test project(M0s, 2.0, 4.0) == 4.0 + @test retract(M0s, 2.0, 4.0) == 6.0 + @test retract(M0s, 2.0, 4.0, ExponentialRetraction()) == 6.0 + + @test ManifoldDiff.adjoint_Jacobi_field( + M0s, + 0.0, + 1.0, + 0.5, + 2.0, + ManifoldDiff.βdifferential_shortest_geodesic_startpoint, + ) === 2.0 + @test ManifoldDiff.diagonalizing_projectors(M0s, 0.0, 2.0) == + ((0.0, ManifoldDiff.IdentityProjector()),) + @test ManifoldDiff.jacobi_field( + M0s, + 0.0, + 1.0, + 0.5, + 2.0, + ManifoldDiff.βdifferential_shortest_geodesic_startpoint, + ) === 2.0 + end end diff --git a/test/manifolds/flag.jl b/test/manifolds/flag.jl index 6df6278aa8..61995d434f 100644 --- a/test/manifolds/flag.jl +++ b/test/manifolds/flag.jl @@ -269,4 +269,11 @@ using Random @test retract(M, p1_ortho, X1_ortho, QRRetraction()).value ≈ retract(OrthogonalMatrices(5), p1_ortho.value, X1_ortho.value, QRRetraction()) end + + @testset "static parameters" begin + M = Flag(5, 1, 2; parameter=:type) + @test Manifolds.get_n(M) == 5 + @test get_embedding(M) == Stiefel(5, 2; parameter=:type) + @test repr(M) == "Flag(5, 1, 2; parameter=:type)" + end end diff --git a/test/manifolds/sphere.jl b/test/manifolds/sphere.jl index 8a32ea0782..734641a9ea 100644 --- a/test/manifolds/sphere.jl +++ b/test/manifolds/sphere.jl @@ -282,4 +282,10 @@ using ManifoldsBase: TFVector @test manifold_volume(Sphere(3)) ≈ 2 * π * π @test volume_density(M, p, [0.0, 0.5, 0.5]) ≈ 0.9187253698655684 end + + @testset "static parameter" begin + @test repr(Sphere(2; parameter=:type)) == "Sphere(2, ℝ; parameter=:type)" + @test repr(ArraySphere(2, 3; parameter=:type)) == + "ArraySphere(2, 3; field = ℝ, parameter=:type)" + end end diff --git a/test/manifolds/unitary_matrices.jl b/test/manifolds/unitary_matrices.jl index cc443c1dfa..3345f116f3 100644 --- a/test/manifolds/unitary_matrices.jl +++ b/test/manifolds/unitary_matrices.jl @@ -5,6 +5,8 @@ using Quaternions @testset "Orthogonal Matrices" begin M = OrthogonalMatrices(3) @test repr(M) == "OrthogonalMatrices(3)" + @test repr(OrthogonalMatrices(3; parameter=:type)) == + "OrthogonalMatrices(3; parameter=:type)" @test injectivity_radius(M, PolarRetraction()) == π / sqrt(2.0) @test manifold_dimension(M) == 3 @test injectivity_radius(M) == π * sqrt(2.0) @@ -22,6 +24,7 @@ end @testset "Unitary Matrices" begin M = UnitaryMatrices(2) @test repr(M) == "UnitaryMatrices(2)" + @test repr(UnitaryMatrices(2; parameter=:type)) == "UnitaryMatrices(2; parameter=:type)" @test manifold_dimension(M) == 4 @test !is_flat(M) @test injectivity_radius(M) == π @@ -75,6 +78,7 @@ end @testset "Quaternionic Unitary Matrices" begin M = UnitaryMatrices(1, ℍ; parameter=:type) @test repr(M) == "UnitaryMatrices(1, ℍ; parameter=:type)" + @test repr(UnitaryMatrices(1, ℍ)) == "UnitaryMatrices(1, ℍ)" @test manifold_dimension(M) == 3 @test injectivity_radius(M) == π @test !is_flat(M)