Skip to content

Commit

Permalink
Fix #539 (#540)
Browse files Browse the repository at this point in the history
* Fix #539

* address review, bump version

* small improvement
  • Loading branch information
mateuszbaran authored Oct 5, 2022
1 parent d817d1c commit c5b4990
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Manifolds"
uuid = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"]
version = "0.8.29"
version = "0.8.30"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
21 changes: 18 additions & 3 deletions src/manifolds/MetricManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,27 @@ struct MetricManifold{𝔽,M<:AbstractManifold{𝔽},G<:AbstractMetric} <:
metric::G
end

function _drop_embedding_type(t::TraitList)
return TraitList(t.head, _drop_embedding_type(t.tail))
end
function _drop_embedding_type(t::TraitList{IsIsometricEmbeddedManifold})
return _drop_embedding_type(t.tail)
end
function _drop_embedding_type(t::TraitList{IsEmbeddedSubmanifold})
return _drop_embedding_type(t.tail)
end
_drop_embedding_type(t::EmptyTrait) = t

function active_traits(f, M::MetricManifold, args...)
at = active_traits(f, M.manifold, args...)
imf = is_metric_function(f)
idm = imf && is_default_metric(M.manifold, M.metric)
return merge_traits(
is_default_metric(M.manifold, M.metric) ? IsDefaultMetric(M.metric) : EmptyTrait(),
idm ? IsDefaultMetric(M.metric) : EmptyTrait(),
IsMetricManifold(),
active_traits(f, M.manifold, args...),
is_metric_function(f) ? EmptyTrait() : IsExplicitDecorator(),
# avoid forwarding to the embedding if the metric is not the default one
idm ? at : _drop_embedding_type(at),
imf ? EmptyTrait() : IsExplicitDecorator(),
)
end
# remetricise instead of double-decorating
Expand Down
17 changes: 17 additions & 0 deletions test/metric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ function Manifolds.vector_transport_along!(
Y .= c
return Y
end

# test for https://github.com/JuliaManifolds/Manifolds.jl/issues/539
struct Issue539Metric <: RiemannianMetric end
Manifolds.inner(::MetricManifold{ℝ,<:AbstractManifold{ℝ},Issue539Metric}, p, X, Y) = 3

@testset "Metrics" begin
# some tests failed due to insufficient accuracy for a particularly bad RNG state
Random.seed!(42)
Expand Down Expand Up @@ -640,4 +645,16 @@ end
Y2 = change_representer(M, G, p, X)
@test Y2 2 .* X #scaled metric has a factor 2, removing introduces this factor
end

@testset "issue #539" begin
M = Sphere(2)
p = [0.49567358314486515, 0.3740229181343087, -0.7838460025302334]
X = [-1.1552859627097727, 0.40665559717366767, -0.5365163797547751]
MM = MetricManifold(M, Issue539Metric())
@test norm(MM, p, X)^2 3
@test Manifolds._drop_embedding_type(
ManifoldsBase.merge_traits(IsEmbeddedSubmanifold()),
) === ManifoldsBase.EmptyTrait()
@test get_embedding(MM) === get_embedding(M)
end
end

2 comments on commit c5b4990

@mateuszbaran
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69597

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.30 -m "<description of version>" c5b4990f05bf3bb1bb1184bd47b5c0cf7da06bad
git push origin v0.8.30

Please sign in to comment.