/
product_group.jl
303 lines (273 loc) · 9.2 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
"""
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 be an [`AbstractGroupManifold`](@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_decorator, manifold.manifolds)
error("All submanifolds of product manifold must be or decorate groups.")
end
op = ProductOperation()
return GroupManifold(manifold, op)
end
function decorator_transparent_dispatch(::typeof(group_exp!), M::ProductGroup, q, X)
return Val(:transparent)
end
function decorator_transparent_dispatch(::typeof(group_log!), M::ProductGroup, X, q)
return Val(:transparent)
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 _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(
e::Identity{GT},
::Val{I},
) where {I,MT<:ProductManifold,𝔽,GT<:GroupManifold{𝔽,MT}}
return Identity(submanifold(e.group, I), submanifold_component(e.p, I))
end
function submanifold_components(
e::Identity{GT},
) where {MT<:ProductManifold,𝔽,GT<:GroupManifold{𝔽,MT}}
M = base_manifold(e.group)
return map(Identity, M.manifolds, submanifold_components(e.group, e.p))
end
Base.inv(G::ProductGroup, p) = inv(G.manifold, p)
Base.inv(::GT, e::Identity{GT}) where {GT<:ProductGroup} = e
function Base.inv(M::ProductManifold, x::ProductRepr)
return ProductRepr(map(inv, M.manifolds, submanifold_components(M, x))...)
end
function Base.inv(M::ProductManifold, p)
q = allocate_result(M, inv, p)
return inv!(M, q, p)
end
inv!(G::ProductGroup, q, p) = inv!(G.manifold, q, p)
function inv!(M::ProductManifold, q, p)
map(inv!, M.manifolds, submanifold_components(M, q), submanifold_components(M, p))
return q
end
Base.identity(G::ProductGroup, p) = identity(G.manifold, p)
Base.identity(::GT, e::Identity{GT}) where {GT<:ProductGroup} = e
function Base.identity(M::ProductManifold, p::ProductRepr)
return ProductRepr(map(identity, M.manifolds, submanifold_components(M, p))...)
end
function Base.identity(M::ProductManifold, p)
q = allocate_result(M, identity, p)
return identity!(M, q, p)
end
identity!(G::ProductGroup, q, p) = identity!(G.manifold, q, p)
function identity!(M::ProductManifold, q, p)
map(identity!, M.manifolds, submanifold_components(M, q), submanifold_components(M, p))
return q
end
compose(G::ProductGroup, p, q) = compose(G.manifold, p, q)
compose(G::GT, ::Identity{GT}, p) where {GT<:ProductGroup} = p
compose(G::GT, p, ::Identity{GT}) where {GT<:ProductGroup} = p
compose(G::GT, e::E, ::E) where {GT<:ProductGroup,E<:Identity{GT}} = e
function compose(M::ProductManifold, p::ProductRepr, q::ProductRepr)
return ProductRepr(map(
compose,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
)...)
end
function compose(M::ProductManifold, p, q)
x = allocate_result(M, compose, p, q)
return compose!(M, x, p, 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
translate(G::ProductGroup, p, q, conv::ActionDirection) = translate(G.manifold, p, q, conv)
function translate(
M::ProductManifold,
p::ProductRepr,
q::ProductRepr,
conv::ActionDirection,
)
return ProductRepr(map(
translate,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
repeated(conv),
)...)
end
function translate(M::ProductManifold, p, q, conv::ActionDirection)
x = allocate_result(M, translate, p, q)
return translate!(M, x, p, q, conv)
end
function translate!(G::ProductGroup, x, p, q, conv::ActionDirection)
return translate!(G.manifold, x, p, q, conv)
end
function translate!(M::ProductManifold, x, p, q, conv::ActionDirection)
map(
translate!,
M.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::ActionDirection)
return inverse_translate(G.manifold, p, q, conv)
end
function inverse_translate(
M::ProductManifold,
p::ProductRepr,
q::ProductRepr,
conv::ActionDirection,
)
return ProductRepr(map(
inverse_translate,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
repeated(conv),
)...)
end
function inverse_translate(M::ProductManifold, p, q, conv::ActionDirection)
x = allocate_result(M, inverse_translate, p, q)
return inverse_translate!(M, x, p, q, conv)
end
function inverse_translate!(G::ProductGroup, x, p, q, conv::ActionDirection)
return inverse_translate!(G.manifold, x, p, q, conv)
end
function inverse_translate!(M::ProductManifold, x, p, q, conv::ActionDirection)
map(
inverse_translate!,
M.manifolds,
submanifold_components(M, x),
submanifold_components(M, p),
submanifold_components(M, q),
repeated(conv),
)
return x
end
function translate_diff(G::ProductGroup, p, q, X, conv::ActionDirection)
return translate_diff(G.manifold, p, q, X, conv)
end
function translate_diff(
M::ProductManifold,
p::ProductRepr,
q::ProductRepr,
X::ProductRepr,
conv::ActionDirection,
)
return ProductRepr(map(
translate_diff,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
submanifold_components(M, X),
repeated(conv),
)...)
end
function translate_diff(M::ProductManifold, p, q, X, conv::ActionDirection)
Y = allocate_result(M, translate_diff, X, p, q)
return translate_diff!(M, Y, p, q, X, conv)
end
function translate_diff!(G::ProductGroup, Y, p, q, X, conv::ActionDirection)
return translate_diff!(G.manifold, Y, p, q, X, conv)
end
function translate_diff!(M::ProductManifold, Y, p, q, X, conv::ActionDirection)
map(
translate_diff!,
M.manifolds,
submanifold_components(M, Y),
submanifold_components(M, p),
submanifold_components(M, q),
submanifold_components(M, X),
repeated(conv),
)
return Y
end
function inverse_translate_diff(G::ProductGroup, p, q, X, conv::ActionDirection)
return inverse_translate_diff(G.manifold, p, q, X, conv)
end
function inverse_translate_diff(
M::ProductManifold,
p::ProductRepr,
q::ProductRepr,
X::ProductRepr,
conv::ActionDirection,
)
return ProductRepr(map(
inverse_translate_diff,
M.manifolds,
submanifold_components(M, p),
submanifold_components(M, q),
submanifold_components(M, X),
repeated(conv),
)...)
end
function inverse_translate_diff(M::ProductManifold, p, q, X, conv::ActionDirection)
Y = allocate_result(M, inverse_translate_diff, X, p, q)
return inverse_translate_diff!(M, Y, p, q, X, conv)
end
function inverse_translate_diff!(G::ProductGroup, Y, p, q, X, conv::ActionDirection)
return inverse_translate_diff!(G.manifold, Y, p, q, X, conv)
end
function inverse_translate_diff!(M::ProductManifold, Y, p, q, X, conv::ActionDirection)
map(
inverse_translate_diff!,
M.manifolds,
submanifold_components(M, Y),
submanifold_components(M, p),
submanifold_components(M, q),
submanifold_components(M, X),
repeated(conv),
)
return Y
end
function group_exp(M::ProductManifold, X::ProductRepr)
return ProductRepr(map(group_exp, M.manifolds, submanifold_components(M, X))...)
end
function group_exp(M::ProductManifold, X)
q = allocate_result(M, group_exp, X)
return group_exp!(M, q, X)
end
function group_exp!(M::ProductManifold, q, X)
map(group_exp!, M.manifolds, submanifold_components(M, q), submanifold_components(M, X))
return q
end
function group_log(M::ProductManifold, q::ProductRepr)
return ProductRepr(map(group_log, M.manifolds, submanifold_components(M, q))...)
end
function group_log(M::ProductManifold, q)
X = allocate_result(M, group_log, q)
return group_log!(M, X, q)
end
function group_log!(M::ProductManifold, X, q)
map(group_log!, M.manifolds, submanifold_components(M, X), submanifold_components(M, q))
return X
end