-
Notifications
You must be signed in to change notification settings - Fork 56
/
multiplication_operation.jl
198 lines (177 loc) · 4.95 KB
/
multiplication_operation.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
"""
MultiplicationOperation <: AbstractGroupOperation
Group operation that consists of multiplication.
"""
struct MultiplicationOperation <: AbstractGroupOperation end
const MultiplicationGroupTrait = TraitList{<:IsGroupManifold{<:MultiplicationOperation}}
Base.:*(e::Identity{MultiplicationOperation}) = e
Base.:*(::Identity{MultiplicationOperation}, p) = p
Base.:*(p, ::Identity{MultiplicationOperation}) = p
Base.:*(e::Identity{MultiplicationOperation}, ::Identity{MultiplicationOperation}) = e
Base.:*(::Identity{MultiplicationOperation}, e::Identity{AdditionOperation}) = e
Base.:*(e::Identity{AdditionOperation}, ::Identity{MultiplicationOperation}) = e
Base.:/(p, ::Identity{MultiplicationOperation}) = p
Base.:/(::Identity{MultiplicationOperation}, p) = inv(p)
Base.:/(e::Identity{MultiplicationOperation}, ::Identity{MultiplicationOperation}) = e
Base.:\(p, ::Identity{MultiplicationOperation}) = inv(p)
Base.:\(::Identity{MultiplicationOperation}, p) = p
Base.:\(e::Identity{MultiplicationOperation}, ::Identity{MultiplicationOperation}) = e
LinearAlgebra.det(::Identity{MultiplicationOperation}) = true
LinearAlgebra.adjoint(e::Identity{MultiplicationOperation}) = e
function identity_element!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
p::AbstractMatrix,
)
return copyto!(p, I)
end
function identity_element!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
p::AbstractArray,
)
if length(p) == 1
fill!(p, one(eltype(p)))
else
throw(DimensionMismatch("Array $p cannot be set to identity element of group $G"))
end
return p
end
function is_identity(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q::Number;
kwargs...,
)
return isapprox(G, q, one(q); kwargs...)
end
function is_identity(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q::AbstractArray{<:Any,0};
kwargs...,
)
return isapprox(G, q[], one(q[]); kwargs...)
end
function is_identity(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q::AbstractMatrix;
kwargs...,
)
return isapprox(G, q, I; kwargs...)
end
LinearAlgebra.mul!(q, ::Identity{MultiplicationOperation}, p) = copyto!(q, p)
LinearAlgebra.mul!(q, p, ::Identity{MultiplicationOperation}) = copyto!(q, p)
function LinearAlgebra.mul!(
q::AbstractMatrix,
::Identity{MultiplicationOperation},
::Identity{MultiplicationOperation},
)
return copyto!(q, I)
end
function LinearAlgebra.mul!(
q,
::Identity{MultiplicationOperation},
::Identity{MultiplicationOperation},
)
return copyto!(q, one(q))
end
function LinearAlgebra.mul!(
q::Identity{MultiplicationOperation},
::Identity{MultiplicationOperation},
::Identity{MultiplicationOperation},
)
return q
end
Base.one(e::Identity{MultiplicationOperation}) = e
Base.inv(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p) = inv(p)
function Base.inv(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
e::Identity{MultiplicationOperation},
)
return e
end
inv!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, q, p) = copyto!(q, inv(G, p))
function inv!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q,
::Identity{MultiplicationOperation},
)
return identity_element!(G, q)
end
function inv!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q::Identity{MultiplicationOperation},
e::Identity{MultiplicationOperation},
)
return q
end
compose(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, q) = p * q
function compose!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, x, p, q)
return mul!_safe(x, p, q)
end
function inverse_translate(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
p,
q,
::LeftForwardAction,
)
return p \ q
end
function inverse_translate(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
p,
q,
::RightBackwardAction,
)
return q / p
end
function inverse_translate!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
x,
p,
q,
conv::ActionDirection,
)
return copyto!(x, inverse_translate(G, p, q, conv))
end
function exp_lie!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
q,
X::Union{Number,AbstractMatrix},
)
copyto!(q, exp(X))
return q
end
function log_lie!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
X::AbstractMatrix,
q::AbstractMatrix,
)
return log_safe!(X, q)
end
function log_lie!(
::MultiplicationGroupTrait,
G::AbstractDecoratorManifold,
X,
::Identity{MultiplicationOperation},
)
return zero_vector!(G, X, identity_element(G))
end
function lie_bracket(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, X, Y)
return mul!(X * Y, Y, X, -1, true)
end
function lie_bracket!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, Z, X, Y)
mul!(Z, X, Y)
mul!(Z, Y, X, -1, true)
return Z
end