Skip to content

Commit

Permalink
implement a general inv_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Nov 13, 2023
1 parent 1301240 commit 63e0b6c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 69 deletions.
9 changes: 1 addition & 8 deletions src/groups/addition_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ end
Compute the value of differential of additive matrix inversion ``p ↦ -p`` at ``X``, i.e. ``-X``.
"""
function inv_diff(::AdditionGroupTrait, G::AbstractDecoratorManifold, p, X)
return -X
end
function inv_diff!(::AdditionGroupTrait, G::AbstractDecoratorManifold, Y, p, X)
Y .= X
Y .*= -1
return Y
end
inv_diff(::AdditionGroupTrait, G::AbstractDecoratorManifold, p, X)

function is_identity(::AdditionGroupTrait, G::AbstractDecoratorManifold, q; kwargs...)
return isapprox(G, q, zero(q); kwargs...)
Expand Down
2 changes: 2 additions & 0 deletions src/groups/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ end

@trait_function inv_diff!(G::AbstractDecoratorManifold, Y, p, X)

inv_diff!(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, Y, p, X) = -adjoint_action!(G, Y, p, X)

Check warning on line 563 in src/groups/group.jl

View workflow job for this annotation

GitHub Actions / Format Check

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/groups/group.jl:563:-inv_diff!(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, Y, p, X) = -adjoint_action!(G, Y, p, X) src/groups/group.jl:573:+function inv_diff!(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, Y, p, X) src/groups/group.jl:574:+ return -adjoint_action!(G, Y, p, X) src/groups/group.jl:575:+end

Check warning on line 563 in src/groups/group.jl

View check run for this annotation

Codecov / codecov/patch

src/groups/group.jl#L563

Added line #L563 was not covered by tests

function Base.copyto!(
::TraitList{IsGroupManifold{O}},
::AbstractDecoratorManifold,
Expand Down
28 changes: 0 additions & 28 deletions src/groups/multiplication_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,6 @@ function inv!(
return q
end

"""
inv_diff(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, X)
Compute the value of differential of matrix inversion ``p ↦ p^{-1}`` at ``X``.
When tangent vectors are represented in Lie algebra in a left-invariant way, the formula
reads ``-pXp^{-1}``. For matrix groups with ambient space tangent vectors, the formula would
read ``-p^{-1}Xp^{-1}``. See the section about matrix inverse in [Giles:2008](@cite).
"""
function inv_diff(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, X)
return -(p * X * inv(G, p))
end
function inv_diff(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
p::AbstractArray{<:Number,0},
X::AbstractArray{<:Number,0},
)
p_inv = inv(p[])
return -(p[] * X * p_inv)
end

function inv_diff!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, Y, p, X)
p_inv = inv(p)
Z = X * p_inv
mul!(Y, p, Z)
Y .*= -1
return Y
end

compose(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, q) = p * q

Expand Down
22 changes: 0 additions & 22 deletions src/groups/power_group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,6 @@ function inv!(
return q
end

function inv_diff!(G::PowerGroup, Y, p, X)
GM = G.manifold
rep_size = representation_size(GM.manifold)
for i in get_iterator(GM)
inv_diff!(
GM.manifold,
_write(GM, rep_size, Y, i),
_read(GM, rep_size, p, i),
_read(GM, rep_size, X, i),
)
end
return Y
end
function inv_diff!(G::PowerGroupNestedReplacing, Y, p, X)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
Y[i...] = inv_diff(N, _read(GM, rep_size, p, i), _read(GM, rep_size, X, i))
end
return Y
end

# lower level methods are added instead of top level ones to not have to deal
# with `Identity` disambiguation
Expand Down
11 changes: 0 additions & 11 deletions src/groups/product_group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ function inv!(G::ProductGroup, q, p)
end
inv!(::ProductGroup, q::Identity{ProductOperation}, ::Identity{ProductOperation}) = q

function inv_diff!(G::ProductGroup, Y, p, X)
M = G.manifold
map(
inv_diff!,
M.manifolds,
submanifold_components(G, Y),
submanifold_components(G, p),
submanifold_components(G, X),
)
return Y
end

_compose(G::ProductGroup, p, q) = _compose(G.manifold, p, q)
function _compose(M::ProductManifold, p::ArrayPartition, q::ArrayPartition)
Expand Down

0 comments on commit 63e0b6c

Please sign in to comment.