Skip to content

Commit

Permalink
run ProductManifold tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Oct 1, 2023
1 parent 75b4826 commit 898e424
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/DefaultManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ function DefaultManifold(n::Vararg{Int}; field = ℝ, parameter::Symbol = :field
return DefaultManifold{field,typeof(size)}(size)
end

function allocation_promotion_function(
::DefaultManifold{ℂ},
::Union{typeof(get_vector),typeof(get_coordinates)},
::Tuple,
)
return complex
end

change_representer!(M::DefaultManifold, Y, ::EuclideanMetric, p, X) = copyto!(M, Y, p, X)

change_metric!(M::DefaultManifold, Y, ::EuclideanMetric, p, X) = copyto!(M, Y, p, X)
Expand Down
4 changes: 3 additions & 1 deletion src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,9 @@ include("PowerManifold.jl")
function __init__()
@static if !isdefined(Base, :get_extension)
@require RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" begin
include("../ext/ManifoldsBaseRecursiveArrayToolsExt.jl")
include(
"../ext/ManifoldsBaseRecursiveArrayToolsExt/ManifoldsBaseRecursiveArrayToolsExt.jl",
)
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions test/product_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,25 @@ include("test_sphere.jl")
end

@testset "Show methods" begin
M2 = ProductManifold(M1, M1, M2, M2)
@test sprint(show, M2) == "ProductManifold($(M1), $(M1), $(M2), $(M2))"
M2p = ProductManifold(M1, M1, M2, M2)
@test sprint(show, M2p) == "ProductManifold($(M1), $(M1), $(M2), $(M2))"
withenv("LINES" => 10, "COLUMNS" => 100) do
@test sprint(show, "text/plain", ProductManifold(M1)) ==
"ProductManifold with 1 submanifold:\n $(M1)"
@test sprint(show, "text/plain", M2) ==
@test sprint(show, "text/plain", M2p) ==
"ProductManifold with 4 submanifolds:\n $(M1)\n $(M1)\n $(M2)\n $(M2)"
return nothing
end
withenv("LINES" => 7, "COLUMNS" => 100) do
@test sprint(show, "text/plain", M2) ==
@test sprint(show, "text/plain", M2p) ==
"ProductManifold with 4 submanifolds:\n $(M1)\n\n $(M2)"
return nothing
end

@test sprint(show, "text/plain", ProductManifold(M, M)) == """
ProductManifold with 2 submanifolds:
ProductManifold(Sphere(2, ℝ), Euclidean(2; field=ℝ))
ProductManifold(Sphere(2, ℝ), Euclidean(2; field=ℝ))"""
ProductManifold($(M1), $(M2))
ProductManifold($(M1), $(M2))"""
end

@testset "product vector transport" begin
Expand Down Expand Up @@ -314,14 +314,14 @@ include("test_sphere.jl")
M,
a,
ArrayPartition([1.0, 0.0, 0.0], [0.0, 0.0]),
[1.0, 2.0, 3.0, 4.0, 5.0], # this is one element too long, hence assertion error
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], # this is one element too long, hence assertion error
B,
)
@test_throws MethodError get_vector!(
M,
a,
ArrayPartition([1.0, 0.0, 0.0], [0.0, 0.0]),
[1.0, 2.0, 3.0, 4.0],
ArrayPartition([1.0, 0.0, 0.0], [0.0 0.0; 0.0 0.0]),
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
B, # empty elements yield a submanifold MethodError
)
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ using ManifoldsBase
include("domain_errors.jl")
include("vector_transport.jl")
include("metric.jl")
include("product_manifold.jl")
include("vector_bundle.jl")
end
20 changes: 20 additions & 0 deletions test/test_sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ TestSphere(N::Int, 𝔽 = ℝ) = TestSphere{N,𝔽}()

ManifoldsBase.representation_size(::TestSphere{N}) where {N} = (N + 1,)

function ManifoldsBase.check_point(M::TestSphere, p; kwargs...)
if !isapprox(norm(p), 1.0; kwargs...)
return DomainError(
norm(p),
"The point $(p) does not lie on the $(M) since its norm is not 1.",
)
end
return nothing
end

function ManifoldsBase.check_vector(M::TestSphere, p, X; kwargs...)
if !isapprox(abs(real(dot(p, X))), 0.0; kwargs...)
return DomainError(
abs(dot(p, X)),
"The vector $(X) is not a tangent vector to $(p) on $(M), since it is not orthogonal in the embedding.",
)
end
return nothing
end

function ManifoldsBase.exp!(M::TestSphere, q, p, X)
return exp!(M, q, p, X, one(number_eltype(X)))
end
Expand Down

0 comments on commit 898e424

Please sign in to comment.