-
Notifications
You must be signed in to change notification settings - Fork 56
/
power_group.jl
401 lines (373 loc) · 11 KB
/
power_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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
const PowerGroup{𝔽,M<:AbstractManifold{𝔽},TPR<:AbstractPowerRepresentation} =
GroupManifold{𝔽,<:AbstractPowerManifold{𝔽,M,TPR},ProductOperation}
"""
PowerGroupNested
Alias to [`PowerGroup`](@ref) with [`NestedPowerRepresentation`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/manifolds.html#ManifoldsBase.NestedPowerRepresentation)
representation.
"""
const PowerGroupNested{𝔽,M<:AbstractManifold{𝔽}} = PowerGroup{𝔽,M,NestedPowerRepresentation}
"""
PowerGroupNestedReplacing
Alias to [`PowerGroup`](@ref) with [`NestedReplacingPowerRepresentation`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/manifolds.html#ManifoldsBase.NestedReplacingPowerRepresentation)
representation.
"""
const PowerGroupNestedReplacing{𝔽,M<:AbstractManifold{𝔽}} =
PowerGroup{𝔽,M,NestedReplacingPowerRepresentation}
"""
PowerGroup{𝔽,T} <: GroupManifold{𝔽,<:AbstractPowerManifold{𝔽,M,RPT},ProductOperation}
Decorate a power manifold with a [`ProductOperation`](@ref).
Constituent manifold of the power manifold 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
PowerGroup(manifold::AbstractPowerManifold)
"""
function PowerGroup(manifold::AbstractPowerManifold)
if !is_group_manifold(manifold.manifold)
error("All powered manifold must be or decorate a group.")
end
op = ProductOperation()
return GroupManifold(manifold, op)
end
function ManifoldsBase._access_nested(
M::PowerManifold,
::Identity{ProductOperation},
i::Tuple,
)
return Identity(M.manifold)
end
@inline function active_traits(f, M::PowerGroup, 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::PowerGroup, p)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
identity_element!(N, _write(GM, rep_size, p, i))
end
return p
end
function identity_element!(G::PowerGroupNestedReplacing, p)
GM = G.manifold
N = GM.manifold
for i in get_iterator(GM)
p[i...] = identity_element(N)
end
return p
end
function is_identity(G::PowerGroup, p::Identity{ProductOperation}; kwargs...)
return true
end
function is_identity(G::PowerGroup, p::Identity; kwargs...)
return false
end
function is_identity(G::PowerGroup, p; kwargs...)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
if !is_identity(N, _read(GM, rep_size, p, i))
return false
end
end
return true
end
inv!(G::PowerGroup, q, ::Identity{ProductOperation}) = identity_element!(G, q)
function inv!(G::PowerGroupNestedReplacing, q, ::Identity{ProductOperation})
return identity_element!(G, q)
end
function inv!(G::PowerGroup, q, p)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
inv!(N, _write(GM, rep_size, q, i), _read(GM, rep_size, p, i))
end
return q
end
function inv!(G::PowerGroupNestedReplacing, q, p)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
q[i...] = inv(N, _read(GM, rep_size, p, i))
end
return q
end
inv!(::PowerGroup, q::Identity{ProductOperation}, ::Identity{ProductOperation}) = q
function inv!(
::PowerGroupNestedReplacing,
q::Identity{ProductOperation},
::Identity{ProductOperation},
)
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
_compose!(G::PowerGroup, x, p, q) = _compose!(G.manifold, x, p, q)
function _compose!(M::AbstractPowerManifold, x, p, q)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
compose!(
N,
_write(M, rep_size, x, i),
_read(M, rep_size, p, i),
_read(M, rep_size, q, i),
)
end
return x
end
function _compose!(M::PowerManifoldNestedReplacing, x, p, q)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
x[i...] = compose(N, _read(M, rep_size, p, i), _read(M, rep_size, q, i))
end
return x
end
function translate!(G::PowerGroup, x, p, q, conv::ActionDirectionAndSide)
return translate!(G.manifold, x, p, q, conv)
end
function translate!(M::AbstractPowerManifold, x, p, q, conv::ActionDirectionAndSide)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
translate!(
N,
_write(M, rep_size, x, i),
_read(M, rep_size, p, i),
_read(M, rep_size, q, i),
conv,
)
end
return x
end
function translate!(M::PowerManifoldNestedReplacing, x, p, q, conv::ActionDirectionAndSide)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
x[i...] = translate(N, _read(M, rep_size, p, i), _read(M, rep_size, q, i), conv)
end
return x
end
function inverse_translate!(G::PowerGroup, x, p, q, conv::ActionDirectionAndSide)
return inverse_translate!(G.manifold, x, p, q, conv)
end
function inverse_translate!(M::AbstractPowerManifold, x, p, q, conv::ActionDirectionAndSide)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
inverse_translate!(
N,
_write(M, rep_size, x, i),
_read(M, rep_size, p, i),
_read(M, rep_size, q, i),
conv,
)
end
return x
end
function inverse_translate!(
M::PowerManifoldNestedReplacing,
x,
p,
q,
conv::ActionDirectionAndSide,
)
N = M.manifold
rep_size = representation_size(N)
for i in get_iterator(M)
x[i...] =
inverse_translate(N, _read(M, rep_size, p, i), _read(M, rep_size, q, i), conv)
end
return x
end
function translate_diff!(G::PowerGroup, Y, p, q, X, conv::ActionDirectionAndSide)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
translate_diff!(
N,
_write(GM, rep_size, Y, i),
_read(GM, rep_size, p, i),
_read(GM, rep_size, q, i),
_read(GM, rep_size, X, i),
conv,
)
end
return Y
end
function translate_diff!(
G::PowerGroupNestedReplacing,
Y,
p,
q,
X,
conv::ActionDirectionAndSide,
)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
Y[i...] = translate_diff(
N,
_read(GM, rep_size, p, i),
_read(GM, rep_size, q, i),
_read(GM, rep_size, X, i),
conv,
)
end
return Y
end
function inverse_translate_diff!(G::PowerGroup, Y, p, q, X, conv::ActionDirectionAndSide)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
inverse_translate_diff!(
N,
_write(GM, rep_size, Y, i),
_read(GM, rep_size, p, i),
_read(GM, rep_size, q, i),
_read(GM, rep_size, X, i),
conv,
)
end
return Y
end
function inverse_translate_diff!(
G::PowerGroupNestedReplacing,
Y,
p,
q,
X,
conv::ActionDirectionAndSide,
)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
Y[i...] = inverse_translate_diff(
N,
_read(GM, rep_size, p, i),
_read(GM, rep_size, q, i),
_read(GM, rep_size, X, i),
conv,
)
end
return Y
end
function exp_lie!(G::PowerGroup, q, X)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
exp_lie!(N, _write(GM, rep_size, q, i), _read(GM, rep_size, X, i))
end
return q
end
function exp_lie!(G::PowerGroupNestedReplacing, q, X)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
q[i...] = exp_lie(N, _read(GM, rep_size, X, i))
end
return q
end
# on this meta level we first pass down before we resolve identity.
function log_lie!(G::PowerGroup, X, q)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
log_lie!(N, _write(GM, rep_size, X, i), _read(GM, rep_size, q, i))
end
return X
end
function log_lie!(G::PowerGroupNestedReplacing, X, q)
GM = G.manifold
N = GM.manifold
rep_size = representation_size(N)
for i in get_iterator(GM)
X[i...] = log_lie(N, _read(GM, rep_size, q, i))
end
return X
end
#overwrite identity case to avoid allocating identity too early.
function log_lie!(G::PowerGroup, X, ::Identity{ProductOperation})
GM = G.manifold
N = GM.manifold
qi = Identity(N)
rep_size = representation_size(N)
for i in get_iterator(GM)
log_lie!(N, _write(GM, rep_size, X, i), qi)
end
return X
end
function log_lie!(G::PowerGroupNestedReplacing, X, ::Identity{ProductOperation})
GM = G.manifold
N = GM.manifold
qi = Identity(N)
for i in get_iterator(GM)
X[i...] = log_lie(N, qi)
end
return X
end
_filter_out_identities() = ()
_filter_out_identities(x, y...) = (x, _filter_out_identities(y...)...)
_filter_out_identities(::Identity, y...) = _filter_out_identities(y...)
function allocate_result(M::PowerGroup, f, x...)
return allocate_result(M.manifold, f, _filter_out_identities(x...)...)
end
function allocate_result(M::PowerGroupNestedReplacing, f, x...)
return allocate_result(M.manifold, f, _filter_out_identities(x...)...)
end
function allocate_result(M::PowerGroup, f::typeof(identity_element))
return allocate_result(M.manifold, f)
end
function allocate_result(M::PowerGroupNestedReplacing, f::typeof(identity_element))
return [allocate_result(M.manifold.manifold, f) for _ in get_iterator(M.manifold)]
end
@inline function _read(
M::AbstractPowerManifold,
::Tuple,
::Identity{ProductOperation},
::Int,
)
return Identity(M.manifold)
end