Skip to content

Commit

Permalink
Add inv.tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer committed Oct 30, 2024
1 parent 8a726a9 commit 834ea73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/group_operations/addition_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ function inv!(::LieGroup{𝔽,AdditionGroupOperation}, h, g) where {𝔽}
h .= (-1) .* g
return h
end
# Resolve ambiguity
function inv!(G::LieGroup{𝔽,O}, q, ::Identity{O}) where {𝔽,O<:AdditionGroupOperation}
return identity_element!(G, q)
end

_doc_lie_bracket_add = """
lie_bracket!(𝔤::LieAlgebra{𝔽,AdditionGroupOperation}, X, Y)
Expand Down
6 changes: 0 additions & 6 deletions src/group_operations/multiplication_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ simplifies to the multiplicative inverse ``g^{-1}``. This can be done in-place o
@doc "$(_doc_inv_mult)"
Base.inv(G::LieGroup{𝔽,<:AbstractMultiplicationGroupOperation}, g) where {𝔽}

function Base.inv(
::LieGroup{𝔽,O}, e::Identity{O}
) where {𝔽,O<:AbstractMultiplicationGroupOperation}
return e
end

@doc "$(_doc_inv_mult)"
function inv!(::LieGroup{𝔽,<:AbstractMultiplicationGroupOperation}, h, g) where {𝔽}
copyto!(h, inv(g))
Expand Down
4 changes: 4 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ function inv! end
@doc "$_doc_inv"
inv!(G::LieGroup, h, g)

function Base.inv(::LieGroup{𝔽,O}, e::Identity{O}) where {𝔽,O<:AbstractGroupOperation}
return e
end

_doc_inv_left_compose = """
inv_left_compose(G::LieGroup, g, h)
inv_left_compose!(G::LieGroup, k, g, h)
Expand Down
39 changes: 38 additions & 1 deletion test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,41 @@ function test_inv_compose(
return nothing
end

"""
test_inv(G::LieGroup, g)
Test the inverse function, both the allocating and the in-place variant,
and that the double inverse is the identity.
# Keyword arguments
* `test_mutating::Bool=true`: test the mutating functions
* `test_identity::Bool=true`: test that `inv(e) == e`
"""
function test_inv(G::LieGroup, g; test_mutating::Bool=true, test_identity::Bool=true)
@testset "inv" begin
k1 = inv(G, g)
@test is_point(G, k1)
g1 = inv(G, k1)
@test isapprox(G, g, g1)
if test_mutating
k2 = copy(G, g)
inv!(G, k2, g)
@test isapprox(G, k1, k2)
# continue in-place
inv!(G, k2, k2)
@test isapprox(G, k2, g)
end
if test_identity
e = Identity(G)
@test inv(G, e) === e
e2 = copy(G, g)
inv!(G, e2, e)
@test is_identity(G, e2)
end
end
return nothing
end
#
#
# --- L
Expand Down Expand Up @@ -660,7 +695,9 @@ function test_lie_group(G::LieGroup, properties::Dict, expectations::Dict=Dict()
test_right=(inv_right_compose in functions),
)
end
#
if (inv in functions)
test_inv(G, points[1]; test_mutating=mutating)
end #
#
# --- L
if (lie_bracket in functions)
Expand Down

0 comments on commit 834ea73

Please sign in to comment.