-
Notifications
You must be signed in to change notification settings - Fork 56
/
product_group.jl
341 lines (304 loc) · 9.47 KB
/
product_group.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
"""
ProductOperation <: AbstractGroupOperation
Direct product group operation.
"""
struct ProductOperation <: AbstractGroupOperation end
const ProductGroup{𝔽,T} = GroupManifold{𝔽,ProductManifold{𝔽,T},ProductOperation}
"""
ProductGroup{𝔽,T} <: GroupManifold{𝔽,ProductManifold{T},ProductOperation}
Decorate a product manifold with a [`ProductOperation`](@ref).
Each submanifold must also have a [`IsGroupManifold`](@ref) or a decorated instance of
one. This type is mostly useful for equipping the direct product of group manifolds with an
[`Identity`](@ref) element.
# Constructor
ProductGroup(manifold::ProductManifold)
"""
function ProductGroup(manifold::ProductManifold{𝔽}) where {𝔽}
if !all(is_group_manifold, manifold.manifolds)
error("All submanifolds of product manifold must be or decorate groups.")
end
op = ProductOperation()
return GroupManifold(manifold, op)
end
@inline function active_traits(f, M::ProductGroup, args...)
if is_metric_function(f)
#pass to manifold by default - but keep Group Decorator for the retraction
return merge_traits(IsGroupManifold(M.op), IsExplicitDecorator())
else
return merge_traits(
IsGroupManifold(M.op),
active_traits(f, M.manifold, args...),
IsExplicitDecorator(),
)
end
end
function identity_element(G::ProductGroup)
M = G.manifold
return ArrayPartition(map(identity_element, M.manifolds))
end
function identity_element!(G::ProductGroup, p)
pes = submanifold_components(G, p)
M = G.manifold
map(identity_element!, M.manifolds, pes)
return p
end
function is_identity(G::ProductGroup, p::Identity{<:ProductOperation}; kwargs...)
pes = submanifold_components(G, p)
M = G.manifold # Inner prodct manifold (of groups)
return all(map((M, pe) -> is_identity(M, pe; kwargs...), M.manifolds, pes))
end
function Base.show(io::IO, ::MIME"text/plain", G::ProductGroup)
print(
io,
"ProductGroup with $(length(base_manifold(G).manifolds)) subgroup$(length(base_manifold(G).manifolds) == 1 ? "" : "s"):",
)
return ManifoldsBase._show_product_manifold_no_header(io, base_manifold(G))
end
function Base.show(io::IO, G::ProductGroup)
M = base_manifold(G)
return print(io, "ProductGroup(", join(M.manifolds, ", "), ")")
end
submanifold(G::ProductGroup, i) = submanifold(base_manifold(G), i)
function submanifold_component(
G::GroupManifold{𝔽,MT,O},
::Identity{O},
::Val{I},
) where {I,MT<:ProductManifold,𝔽,O}
M = G.manifold
# the identity on a product manifold with is a group consists of a tuple of identities
return Identity(M.manifolds[I])
end
function submanifold_components(
G::GroupManifold{𝔽,MT,O},
::Identity{O},
) where {MT<:ProductManifold,𝔽,O<:AbstractGroupOperation}
M = base_manifold(G)
return map(N -> Identity(N), M.manifolds)
end
function submanifold_components(M::ProductGroup, ::Identity{ProductOperation})
return map(N -> Identity(N), M.manifold.manifolds)
end
inv!(G::ProductGroup, q, ::Identity{ProductOperation}) = identity_element!(G, q)
function inv!(G::ProductGroup, q, p)
M = G.manifold
map(inv!, M.manifolds, submanifold_components(G, q), submanifold_components(G, p))
return q
end
inv!(::ProductGroup, q::Identity{ProductOperation}, ::Identity{ProductOperation}) = q
_compose(G::ProductGroup, p, q) = _compose(G.manifold, p, q)
function _compose(M::ProductManifold, p::ArrayPartition, q::ArrayPartition)
return ArrayPartition(
map(
compose,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
)...,
)
end
_compose!(G::ProductGroup, x, p, q) = _compose!(G.manifold, x, p, q)
function _compose!(M::ProductManifold, x, p, q)
map(
compose!,
M.manifolds,
submanifold_components(M, x),
submanifold_components(M, p),
submanifold_components(M, q),
)
return x
end
function translate(
M::ProductGroup,
p::ArrayPartition,
q::ArrayPartition,
conv::ActionDirectionAndSide,
)
return ArrayPartition(
map(
translate,
M.manifold.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
repeated(conv),
)...,
)
end
function translate!(M::ProductGroup, x, p, q, conv::ActionDirectionAndSide)
map(
translate!,
M.manifold.manifolds,
submanifold_components(M, x),
submanifold_components(M, p),
submanifold_components(M, q),
repeated(conv),
)
return x
end
function inverse_translate(G::ProductGroup, p, q, conv::ActionDirectionAndSide)
M = G.manifold
return ArrayPartition(
map(
inverse_translate,
M.manifolds,
submanifold_components(G, p),
submanifold_components(G, q),
repeated(conv),
)...,
)
end
function inverse_translate!(G::ProductGroup, x, p, q, conv::ActionDirectionAndSide)
M = G.manifold
map(
inverse_translate!,
M.manifolds,
submanifold_components(G, x),
submanifold_components(G, p),
submanifold_components(G, q),
repeated(conv),
)
return x
end
function translate_diff(G::ProductGroup, p, q, X, conv::ActionDirectionAndSide)
M = G.manifold
return ArrayPartition(
map(
translate_diff,
M.manifolds,
submanifold_components(G, p),
submanifold_components(G, q),
submanifold_components(G, X),
repeated(conv),
)...,
)
end
function translate_diff!(G::ProductGroup, Y, p, q, X, conv::ActionDirectionAndSide)
M = G.manifold
map(
translate_diff!,
M.manifolds,
submanifold_components(G, Y),
submanifold_components(G, p),
submanifold_components(G, q),
submanifold_components(G, X),
repeated(conv),
)
return Y
end
function inverse_translate_diff(G::ProductGroup, p, q, X, conv::ActionDirectionAndSide)
M = G.manifold
return ArrayPartition(
map(
inverse_translate_diff,
M.manifolds,
submanifold_components(G, p),
submanifold_components(G, q),
submanifold_components(G, X),
repeated(conv),
)...,
)
end
function inverse_translate_diff!(G::ProductGroup, Y, p, q, X, conv::ActionDirectionAndSide)
M = G.manifold
map(
inverse_translate_diff!,
M.manifolds,
submanifold_components(G, Y),
submanifold_components(G, p),
submanifold_components(G, q),
submanifold_components(G, X),
repeated(conv),
)
return Y
end
function Base.exp(M::ProductGroup, p::Identity{ProductOperation}, X::ArrayPartition)
return ArrayPartition(
map(
exp,
M.manifold.manifolds,
submanifold_components(M, p),
submanifold_components(M, X),
)...,
)
end
function exp!(M::ProductGroup, q, p::Identity{ProductOperation}, X)
map(
exp!,
M.manifold.manifolds,
submanifold_components(M, q),
submanifold_components(M, p),
submanifold_components(M, X),
)
return q
end
function exp_lie(G::ProductGroup, X)
M = G.manifold
return ArrayPartition(map(exp_lie, M.manifolds, submanifold_components(G, X))...)
end
function exp_lie!(G::ProductGroup, q, X)
M = G.manifold
map(exp_lie!, M.manifolds, submanifold_components(G, q), submanifold_components(G, X))
return q
end
function Base.log(M::ProductGroup, p::Identity{ProductOperation}, q::ArrayPartition)
return ArrayPartition(
map(
log,
M.manifold.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
)...,
)
end
function log!(M::ProductGroup, X, p::Identity{ProductOperation}, q)
map(
log!,
M.manifold.manifolds,
submanifold_components(M, X),
submanifold_components(M, p),
submanifold_components(M, q),
)
return X
end
# on this meta level we first pass down before we resolve identity.
function log_lie!(G::ProductGroup, X, q)
M = G.manifold
map(log_lie!, M.manifolds, submanifold_components(G, X), submanifold_components(G, q))
return X
end
#overwrite identity case to avoid allocating identity too early.
function log_lie!(G::ProductGroup, X, q::Identity{ProductOperation})
M = G.manifold
map(log_lie!, M.manifolds, submanifold_components(G, X), submanifold_components(G, q))
return X
end
Base.@propagate_inbounds function Base.getindex(
p::ArrayPartition,
M::ProductGroup,
i::Union{Integer,Colon,AbstractVector,Val},
)
return getindex(p, base_manifold(M), i)
end
Base.@propagate_inbounds function Base.setindex!(
q::ArrayPartition,
p,
M::ProductGroup,
i::Union{Integer,Colon,AbstractVector,Val},
)
return setindex!(q, p, base_manifold(M), i)
end
# these isapprox methods are here just to reduce time-to-first-isapprox
function isapprox(G::ProductGroup, p::ArrayPartition, q::ArrayPartition; kwargs...)
return isapprox(G.manifold, p, q; kwargs...)
end
function isapprox(
G::ProductGroup,
p::ArrayPartition,
X::ArrayPartition,
Y::ArrayPartition;
kwargs...,
)
return isapprox(G.manifold, p, X, Y; kwargs...)
end
function isapprox(G::ProductGroup, ::Identity{ProductOperation}, X, Y; kwargs...)
return isapprox(G.manifold, identity_element(G), X, Y; kwargs...)
end