Skip to content

Commit

Permalink
add rand tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer committed Oct 30, 2024
1 parent 2312845 commit 8b193eb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
65 changes: 64 additions & 1 deletion test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The following functions are expected to be available, since their defaults just
"""
module LieGroupsTestSuite
using LieGroups
using Test
using Test, Random

#
#
Expand Down Expand Up @@ -559,6 +559,60 @@ function test_lie_bracket(G::LieGroup, X, Y; expected=missing, test_mutating::Bo
end
end

#
#
# --- R
"""
test_rand(G::LieGroup)
Test the random function, both the allocating and the in-place variant,
as well as the variant with an `rng`, if one is provided.
both the random point and the random tangent vector variants are tested.
# Keyword arguments
* `test_mutating::Bool=true`: test the mutating functions
* `rng=:missing`: test with a specific rng
"""
function test_rand(
G::LieGroup, g; test_mutating::Bool=true, rng::Union{Missing,AbstractRNG}=missing
)
@testset "rand" begin
g1 = rand(G)
@test is_point(G, g1)
if test_mutating
g2 = copy(G, g)
rand!(G, g2)
@test is_point(G, g2)
end
X1 = rand(G; vector_at=g1)
@test is_vector(G, g1, X1)
if test_mutating
X2 = zero_vector(LieAlgebra(G), g1)
rand!(G, X2; vector_at=g1)
@test is_vector(G, g1, X2)
end
if !ismissing(rng)
g1 = rand(rng, G)
@test is_point(G, g1)
if test_mutating
g2 = copy(G, g)
rand!(rng, G, g2)
@test is_point(G, g2)
end
X1 = rand(rng, G; vector_at=g1)
@test is_vector(G, g1, X1)
if test_mutating
X2 = zero_vector(LieAlgebra(G), g1)
rand!(rng, G, X2; vector_at=g1)
@test is_vector(G, g1, X2)
end
end
end
return nothing
end

#
#
# --- S
Expand Down Expand Up @@ -594,6 +648,7 @@ Possible properties are
* `:Vectors` is a vector of at least 3 elements from the Lie algebra `𝔤` og `G`
* `:Mutating` is a boolean (`true` by default) whether to test the mutating variants of functions or not.
* `:Name` is a name of the test. If not provided, defaults to `"\$G"`
* `:Rng` is a random number generator, if provided, the random functions are tested with this generator as well
Possible `expectations` are
Expand Down Expand Up @@ -705,6 +760,14 @@ function test_lie_group(G::LieGroup, properties::Dict, expectations::Dict=Dict()
test_lie_bracket(G, vectors[1], vectors[2]; expected=v, test_mutating=mutating)
end

#
#
# --- R
if (rand in functions)
v = get(properties, :Rng, missing)
test_rand(G, points[1]; rng=v, test_mutating=mutating)
end

#
#
# --- S
Expand Down
4 changes: 3 additions & 1 deletion test/groups/test_general_linear_group.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LieGroups, Test
using LieGroups, Random, Test

s = joinpath(@__DIR__, "..", "LieGroupsTestSuite.jl")
!(s in LOAD_PATH) && (push!(LOAD_PATH, s))
Expand All @@ -12,6 +12,7 @@ begin
:Name => "The general linear group",
:Points => [g1, g2, g3],
:Vectors => [X1, X2, X3],
:Rng => Random.MersenneTwister(),
:Functions => [
compose,
conjugate,
Expand All @@ -26,6 +27,7 @@ begin
is_identity,
lie_bracket,
log,
#rand, # requires a fix in Manifolds.jl to have rand on invertive matrices
show,
],
)
Expand Down
4 changes: 3 additions & 1 deletion test/groups/test_translation_group.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LieGroups, Test
using LieGroups, Random, Test

s = joinpath(@__DIR__, "..", "LieGroupsTestSuite.jl")
!(s in LOAD_PATH) && (push!(LOAD_PATH, s))
Expand All @@ -12,6 +12,7 @@ begin
:Name => "The Translation group",
:Points => [g1, g2, g3],
:Vectors => [X1, X2, X3],
:Rng => Random.MersenneTwister(),
:Functions => [
adjoint,
compose,
Expand All @@ -27,6 +28,7 @@ begin
is_identity,
lie_bracket,
log,
rand,
show,
],
)
Expand Down

0 comments on commit 8b193eb

Please sign in to comment.