Skip to content

Commit 3010a30

Browse files
committed
add SpecialEuclidean(3) test
1 parent 283152d commit 3010a30

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/manifolds/manifolddiff.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using ManifoldsBase
66
using Manifolds, Manopt
77
import Optim
88
using FiniteDifferences, ManifoldDiff
9+
import Rotations as _Rot
910

1011
##
1112

@@ -159,5 +160,49 @@ Cq .= randn(3)
159160
@test isapprox( f(sol.minimizer), 0; atol=1e-8 )
160161
@test isapprox( 0, sum(abs.(log(M, e0, compose(M, inv(M,q), sol.minimizer)))); atol=1e-5)
161162

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+
162207
##
163208
end

0 commit comments

Comments
 (0)