Skip to content

Commit

Permalink
adds a test for positive vectors and starts testing the default Metri…
Browse files Browse the repository at this point in the history
…c fallbacks using the local metric.
  • Loading branch information
kellertuer committed Sep 16, 2021
1 parent 5005965 commit 95a3c8b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/manifolds/HyperbolicHyperboloid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ function change_representer!(M::Hyperbolic, Y, ::EuclideanMetric, p, X)
return Y
end

# a metric change does not seem possible here
function change_metric(::Hyperbolic, ::EuclideanMetric, ::Any, ::Any)
return error(
"Changing metric from Euclidean to Hyperbolic is not possible (see Sylvester's law of inertia).",
)
end

function check_point(M::Hyperbolic, p; kwargs...)
mpv = invoke(check_point, Tuple{supertype(typeof(M)),typeof(p)}, M, p; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/manifolds/MetricManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function change_metric!(M::AbstractManifold, Y, G::AbstractMetric, p, X)
# TODO: For local metric, inverse_local metric, det_local_metric: Introduce a default basis?
B = DefaultOrthogonalBasis()
G1 = local_metric(M, p, B)
G2 = localMetric(G(M), p, B)
G2 = local_metric(G(M), p, B)
x = get_coordinates(M, p, X, B)
C1 = cholesky(G1).L
C2 = cholesky(G2).L
Expand Down
2 changes: 1 addition & 1 deletion test/manifolds/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ include("../utils.jl")
Y = change_representer(M, EuclideanMetric(), p, X)
@test inner(M, p, X, Y) == inner(Euclidean(3), p, X, X)
# change metric not possible from Euclidean, since the embedding is Lorenzian
@test_throws MethodError change_metric(M, EuclideanMetric(), p, X)
@test_throws ErrorException change_metric(M, EuclideanMetric(), p, X)
# but if we come from the same metric, we have the identity
@test change_metric(M, MinkowskiMetric(), p, X) == X
end
Expand Down
3 changes: 3 additions & 0 deletions test/manifolds/positive_numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ include("../utils.jl")

@test change_metric(M, EuclideanMetric(), 2, 3) == 3 * 2
@test change_representer(M, EuclideanMetric(), 2, 3) == 3 * 2^2
N = PositiveVectors(2)
@test change_metric(M, EuclideanMetric(), [1, 2], [3, 4]) == [3, 4 * 2]
@test change_representer(M, EuclideanMetric(), [1, 2], [3, 4]) == [3, 4 * 2^2]
end
types = [Float64]
TEST_FLOAT32 && push!(types, Float32)
Expand Down
18 changes: 17 additions & 1 deletion test/metric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include("utils.jl")

struct TestEuclidean{N} <: AbstractManifold{ℝ} end
struct TestEuclideanMetric <: AbstractMetric end
struct TestScaledEuclideanMetric <: AbstractMetric end

Manifolds.manifold_dimension(::TestEuclidean{N}) where {N} = N
function Manifolds.local_metric(
Expand All @@ -19,10 +20,17 @@ end
function Manifolds.local_metric(
M::MetricManifold{ℝ,<:TestEuclidean,<:TestEuclideanMetric},
::Any,
::InducedBasis,
::DefaultOrthonormalBasis,
)
return Diagonal(1.0:manifold_dimension(M))
end
function Manifolds.local_metric(
M::MetricManifold{ℝ,<:TestEuclidean,<:TestScaledEuclideanMetric},
::Any,
::DefaultOrthonormalBasis,
)
return 2 .* Diagonal(1.0:manifold_dimension(M))
end

struct TestSphere{N,T} <: AbstractManifold{ℝ}
r::T
Expand Down Expand Up @@ -603,4 +611,12 @@ end
ExponentialRetraction(),
) === Val{:parent}()
end

@testset "change metric and representer" begin
M = MetricManifold(TestEuclidean{2}(), TestEuclideanMetric())
G = TestScaledEuclideanMetric()
p = ones(2)
X = 2 * ones(2)
Y = change_metric(M, G, p, X)
end
end

0 comments on commit 95a3c8b

Please sign in to comment.