@@ -6,6 +6,7 @@ using ManifoldsBase
6
6
using Manifolds, Manopt
7
7
import Optim
8
8
using FiniteDifferences, ManifoldDiff
9
+ import Rotations as _Rot
9
10
10
11
# #
11
12
@@ -159,5 +160,49 @@ Cq .= randn(3)
159
160
@test isapprox ( f (sol. minimizer), 0 ; atol= 1e-8 )
160
161
@test isapprox ( 0 , sum (abs .(log (M, e0, compose (M, inv (M,q), sol. minimizer)))); atol= 1e-5 )
161
162
163
+ # #
164
+ end
165
+
166
+
167
+ @testset " Modified ManifoldsWrapper for Optim.Manifolds, SpecialEuclidean(3)" begin
168
+ # #
169
+
170
+
171
+ M = Manifolds. SpecialEuclidean (3 )
172
+ e0 = ArrayPartition ([0 ,0 ,0. ], Matrix (_Rot. RotXYZ (0 ,0 ,0. )))
173
+
174
+ x0 = deepcopy (e0)
175
+ Cq = 0.5 * randn (6 )
176
+ q = exp (M,e0,hat (M,e0,Cq))
177
+
178
+ f (p) = distance (M, p, q)^ 2
179
+
180
+ # # finitediff gradient (non-manual)
181
+ function g_FD! (X,p)
182
+ X .= ManifoldDiff. gradient (M, f, p, r_backend)
183
+ X
184
+ end
185
+
186
+ # # sanity check gradients
187
+
188
+ X = hat (M, e0, zeros (6 ))
189
+ g_FD! (X, q)
190
+ # gradient at the optimal point should be zero
191
+ @test isapprox (0 , sum (abs .(X[:])); atol= 1e-8 )
192
+
193
+ # gradient not the optimal point should be non-zero
194
+ g_FD! (X, e0)
195
+ @test 0.01 < sum (abs .(X[:]))
196
+
197
+ # # do optimization
198
+ x0 = deepcopy (e0)
199
+ sol = Optim. optimize (f, g_FD!, x0, Optim. ConjugateGradient (; manifold= ManifoldWrapper (M)))
200
+ Cq .= 0.5 * randn (6 )
201
+ # Cq[
202
+ @show sol. minimizer
203
+ @test isapprox ( f (sol. minimizer), 0 ; atol= 1e-8 )
204
+ @test isapprox ( 0 , sum (abs .(log (M, e0, compose (M, inv (M,q), sol. minimizer)))); atol= 1e-5 )
205
+
206
+
162
207
# #
163
208
end
0 commit comments