diff --git a/Project.toml b/Project.toml index 182080ba..1307f3be 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ManifoldsBase" uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb" authors = ["Seth Axen ", "Mateusz Baran ", "Ronny Bergmann ", "Antoine Levitt "] -version = "0.13.14" +version = "0.13.15" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/ManifoldsBase.jl b/src/ManifoldsBase.jl index 1ac56dc9..9f810a7d 100644 --- a/src/ManifoldsBase.jl +++ b/src/ManifoldsBase.jl @@ -283,6 +283,16 @@ If ``\mathcal M`` is not connected, i.e. consists of several disjoint components the distance between two points from different components should be ``∞``. """ distance(M::AbstractManifold, p, q) = norm(M, p, log(M, p, q)) +""" + distance(M::AbstractManifold, p, q, m::AbstractInverseRetractionMethod) + +Approximate distance between points `p` and `q` on manifold `M` using +[`AbstractInverseRetractionMethod`](@ref) `m`. +""" +function distance(M::AbstractManifold, p, q, m::AbstractInverseRetractionMethod) + return norm(M, p, inverse_retract(M, p, q, m)) +end +distance(M::AbstractManifold, p, q, ::LogarithmicInverseRetraction) = distance(M, p, q) """ embed(M::AbstractManifold, p) diff --git a/test/default_manifold.jl b/test/default_manifold.jl index bd360859..069ac2b8 100644 --- a/test/default_manifold.jl +++ b/test/default_manifold.jl @@ -52,7 +52,7 @@ function ManifoldsBase._retract(M::DefaultManifold, p, X, ::CustomDefinedRetract return retract_custom(M, p, X) end function retract_custom(::DefaultManifold, p::DefaultPoint, X::DefaultTVector) - return DefaultPoint(p.value + X.value) + return DefaultPoint(2 * p.value + X.value) end function ManifoldsBase._inverse_retract( M::DefaultManifold, @@ -63,7 +63,7 @@ function ManifoldsBase._inverse_retract( return inverse_retract_custom(M, p, q) end function inverse_retract_custom(::DefaultManifold, p::DefaultPoint, q::DefaultPoint) - return DefaultTVector(q.value - p.value) + return DefaultTVector(q.value - 2 * p.value) end struct MatrixVectorTransport{T} <: AbstractVector{T} m::Matrix{T} @@ -210,6 +210,8 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),) @test isapprox(M, exp(M, pts[1], tv1, 0), pts[1]) @test distance(M, pts[1], pts[2]) ≈ norm(M, pts[1], tv1) + @test distance(M, pts[1], pts[2], LogarithmicInverseRetraction()) ≈ + norm(M, pts[1], tv1) @test mid_point(M, pts[1], pts[2]) == convert(T, [0.5, 0.5, 0.0]) midp = allocate(pts[1]) @@ -549,7 +551,8 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),) @test X3 == log(M, p, q) @test log!(M, X3, p, q) == log(M, p, q) @test X3 == log(M, p, q) - @test inverse_retract(M, p, q, CustomDefinedInverseRetraction()) == -Y + @test inverse_retract(M, p, q, CustomDefinedInverseRetraction()) == -2 * Y + @test distance(M, p, q, CustomDefinedInverseRetraction()) == 2.0 X4 = ManifoldsBase.allocate_result(M, inverse_retract, p, q) @test inverse_retract!(M, X4, p, q) == inverse_retract(M, p, q) @test X4 == inverse_retract(M, p, q)