Skip to content

Commit

Permalink
tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Oct 2, 2023
1 parent 898e424 commit fc94b74
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
28 changes: 24 additions & 4 deletions test/product_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ include("test_sphere.jl")

M = ProductManifold(M1, M2)

p1 = ArrayPartition([1, 0.0, 0.0], [4 5.0; 6 7])
p2 = ArrayPartition([0.0, 1.0, 0.0], [4 8.0; 3 7.5])
@test_throws MethodError ProductManifold()

p1 = ArrayPartition([1, 0.0, 0.0], [4.0 5.0; 6.0 7.0])
p2 = ArrayPartition([0.0, 1.0, 0.0], [4.0 8.0; 3.0 7.5])

@test !is_flat(M)
@test M[1] == M1
Expand Down Expand Up @@ -102,8 +104,26 @@ include("test_sphere.jl")
@test q[1].x[1] isa Vector
end

p1 = ArrayPartition([1, 0.0, 0.0], [4 5.0; 6 7])
p2 = ArrayPartition([0.0, 1.0, 0.0], [4 8.0; 3 7.5])
p1 = ArrayPartition([1.0, 0.0, 0.0], [4.0 5.0; 6.0 7.0])
p2 = ArrayPartition([0.0, 1.0, 0.0], [4.0 8.0; 3.0 7.5])
X1 = ArrayPartition([0.0, 1.0, 0.2], [4.0 0.0; 2.0 7.0])

@testset "Basic operations" begin
@test distance(M, p1, p2) 4.551637188998299
qr = similar(p1)
exp!(M, qr, p1, X1)
@test exp(M, p1, X1) ArrayPartition(
[0.5235330372543839, 0.8354600062374664, 0.1670920012474933],
[8.0 5.0; 8.0 14.0],
)
@test exp(M, p1, X1) qr
@test exp(M, p1, X1, 2.0) exp(M, p1, 2 * X1)
Xr = similar(X1)
log!(M, Xr, p1, p2)
@test log(M, p1, p2)
ArrayPartition([0.0, 1.5707963267948966, 0.0], [0.0 3.0; -3.0 0.5])
@test log(M, p1, p2) Xr
end

@testset "Broadcasting" begin
br_result = p1 .+ 2.0 .* p2
Expand Down
2 changes: 1 addition & 1 deletion test/test_sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function ManifoldsBase.exp!(M::TestSphere, q, p, X)
return exp!(M, q, p, X, one(number_eltype(X)))
end
function ManifoldsBase.exp!(::TestSphere, q, p, X, t::Number)
θ = norm(X)
θ = abs(t) * norm(X)
if θ == 0
copyto!(q, p)
else
Expand Down
48 changes: 48 additions & 0 deletions test/vector_bundle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using RecursiveArrayTools, ManifoldsBase, Test
using ManifoldsBase: DefaultManifold, VectorSpaceType, VectorSpaceFiberType, ℝ, FiberAtPoint
struct TestVectorSpaceType <: VectorSpaceType end

include("test_sphere.jl")

@testset "Tangent bundle" begin
M = DefaultManifold(3)
m_prod_retr = ManifoldsBase.FiberBundleProductRetraction()
Expand All @@ -23,11 +25,16 @@ struct TestVectorSpaceType <: VectorSpaceType end
@test default_retraction_method(TB) == m_prod_retr
@test default_vector_transport_method(TB) isa
ManifoldsBase.FiberBundleProductVectorTransport
@test TB ===
VectorBundle(TangentSpace, M, ManifoldsBase.FiberBundleProductVectorTransport())
CTB = CotangentBundle(M)
@test sprint(show, CTB) == "CotangentBundle($(M))"
@test sprint(show, VectorBundle(TestVectorSpaceType(), M)) ==
"VectorBundle(TestVectorSpaceType(), $(M))"

@test vector_space_dimension(TB.fiber) == 3
@test vector_space_dimension(CTB.fiber) == 3

@testset "spaces at point" begin
p = [1.0, 0.0, 0.0]
t_p = TangentSpaceAtPoint(M, p)
Expand Down Expand Up @@ -100,3 +107,44 @@ struct TestVectorSpaceType <: VectorSpaceType end
@test_throws DomainError view(p, TB, :error)
end
end

@testset "Tangent bundle of a sphere" begin
M = TestSphere(2)
TM = TangentBundle(M)
pm = [1.0, 0.0, 0.0]
Xm = [0.0, 1.0, -2.0]
Ym = [0.0, -1.0, 2.0]
p1 = ArrayPartition(pm, Xm)
X1 = ArrayPartition(Xm, Ym)
X2 = ArrayPartition(Ym, Xm)
@test distance(TM.fiber, pm, Xm, Ym) sqrt(20)
@test injectivity_radius(TM) == 0.0
@test ManifoldsBase.fiber_dimension(TM.fiber) == 2

qm = exp(M, pm, Xm)
Xt = vector_transport_direction(TM, p1, X1, X2)
p2 = ArrayPartition(
[1.7592245393784949, -0.6172728764571667, 1.2345457529143333],
[-1.7592245393784949, 0.6172728764571667, -1.2345457529143333],
)
Yt = similar(Xt)
vector_transport_direction!(TM, Yt, p1, X1, X2)
@test isapprox(Xt, p2)
@test isapprox(Yt, p2)

p3 = ArrayPartition(exp(M, pm, Xm), parallel_transport_direction(M, pm, Ym, Xm))
X3 = ArrayPartition(
[-1.7592245393784949, -0.6172728764571667, 1.2345457529143333],
[1.7592245393784949, 0.6172728764571667, -1.2345457529143333],
)
Yt = similar(Xt)
vector_transport_to!(TM, Yt, p1, X1, p3)
@test isapprox(vector_transport_to(TM, p1, X1, p3), X3)
@test isapprox(Yt, X3)
@test zero_vector(TM, p1) == zero(p1)

X1c = get_coordinates(TM, p1, X1, DefaultOrthonormalBasis())
@test isapprox(X1c, [1.0, -2.0, -1.0, 2.0])
@test isapprox(get_vector(TM, p1, X1c, DefaultOrthonormalBasis()), X1)

end

0 comments on commit fc94b74

Please sign in to comment.