Skip to content

Commit

Permalink
Introduce has_components for Euclidean (#759)
Browse files Browse the repository at this point in the history
* Adapt Euclidean to ManifoldsBase 0.15.18 to the r-norms feature.
* Improve docs, start Test suite.
* Move this to 0.10.4
  • Loading branch information
kellertuer authored Oct 20, 2024
1 parent 5d28783 commit b3c0fa4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* `uniform_distribution` now has an error hint explaining what has to be done to make it work.
* `Euclidean` now follows the new `has_components` function from `ManifoldsBase.jl` (0.15.18)
and can handle also the `r`-norms now.
- Union type `MatrixGroup`
- Columnwise group action with arbitrary matrix groups
- `uniform_distribution` now has an error hint explaining what has to be done to make it work.
Expand All @@ -22,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

* Fixed `solve_exp_ode` only returning the starting position ([#744](https://github.com/JuliaManifolds/Manifolds.jl/issues/744))
* Fixed documentation of `solve_exp_ode` function signature ([#740](https://github.com/JuliaManifolds/Manifolds.jl/issues/740))
* Fixed documentation of `solve_exp_ode` function signature ([#740](https://github.com/JuliaManifolds/Manifolds.jl/issues/740))

## [0.10.2] - 2024-09-24

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HybridArrays = "0.4"
Kronecker = "0.4, 0.5"
LinearAlgebra = "1.6"
ManifoldDiff = "0.3.7"
ManifoldsBase = "0.15.17"
ManifoldsBase = "0.15.18"
Markdown = "1.6"
MatrixEquations = "2.2"
NLsolve = "4"
Expand Down
2 changes: 2 additions & 0 deletions src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import ManifoldsBase:
get_vector_orthonormal!,
get_vectors,
gram_schmidt,
has_components,
hat,
hat!,
injectivity_radius,
Expand Down Expand Up @@ -870,6 +871,7 @@ export ×,
get_embedding,
get_orbit_action,
get_total_space,
has_components,
hat,
hat!,
horizontal_component,
Expand Down
22 changes: 17 additions & 5 deletions src/manifolds/Euclidean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ function diagonalizing_projectors(::Euclidean, p, X)
end

"""
distance(M::Euclidean, p, q)
distance(M::Euclidean, p, q, r::Real=2)
Compute the Euclidean distance between two points on the [`Euclidean`](@ref)
manifold `M`, i.e. for vectors it's just the norm of the difference, for matrices
and higher order arrays, the matrix and tensor Frobenius norm, respectively.
Specifying further an `r≠2`, other norms, like the 1-norm or the ∞-norm can also be computed.
"""
Base.@propagate_inbounds function distance(M::Euclidean, p, q)
# Inspired by euclidean distance calculation in Distances.jl
Expand All @@ -154,6 +155,7 @@ Base.@propagate_inbounds function distance(M::Euclidean, p, q)
end
return sqrt(s)
end
distance(M::Euclidean, p, q, r::Real) = norm(p - q, r)
distance(::Euclidean{TypeParameter{Tuple{1}}}, p::Number, q::Number) = abs(p - q)
distance(::Euclidean{TypeParameter{Tuple{}}}, p::Number, q::Number) = abs(p - q)
distance(::Euclidean{Tuple{Int}}, p::Number, q::Number) = abs(p - q) # for 1-dimensional Euclidean
Expand Down Expand Up @@ -390,6 +392,9 @@ function get_vector_diagonalizing!(
copyto!(Y, reshape(c[1:N] + im * c[(N + 1):end], S))
return Y
end

has_components(::Euclidean) = true

@doc raw"""
injectivity_radius(M::Euclidean)
Expand Down Expand Up @@ -631,14 +636,21 @@ function mid_point!(::Euclidean, q, p1, p2)
end

@doc raw"""
norm(M::Euclidean, p, X)
norm(M::Euclidean, p, X, r::Real=2)
Compute the norm of a tangent vector `X` at `p` on the [`Euclidean`](@ref)
`M`, i.e. since every tangent space can be identified with `M` itself
in this case, just the (Frobenius) norm of `X`.
in this case, just the (Frobenius) norm of `X`. Specifying `r`, other norms are available as well
"""
LinearAlgebra.norm(::Euclidean, ::Any, X) = norm(X)
LinearAlgebra.norm(::MetricManifold{ℝ,<:AbstractManifold,EuclideanMetric}, p, X) = norm(X)
LinearAlgebra.norm(::Euclidean, ::Any, X, r::Real=2) = norm(X, r)
function LinearAlgebra.norm(
::MetricManifold{ℝ,<:AbstractManifold,EuclideanMetric},
p,
X,
r::Real=2,
)
return norm(X, r)
end

function project!(
::EmbeddedManifold{𝔽,Euclidean{nL,𝔽},Euclidean{mL,𝔽2}},
Expand Down
18 changes: 18 additions & 0 deletions test/ManifoldsTestSuite.jl/ManifoldsTestSuite.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
ManifoldsTestSuite.jl
An internal small module to encapsulate
* dummy types
* test functions
* a test suite
This is a slow work-in-progress to replace the `test_manifold` function,
and encapsulate and collect common tools for testing a manifold.
The current plan is to slowly move parts to this test suite whenever revising some tests or¨
time permits.
"""
module ManifoldsTestSuite

end
10 changes: 10 additions & 0 deletions test/manifolds/euclidean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ using FiniteDifferences
A = Manifolds.RetractionAtlas()
B = induced_basis(EM, A, p, TangentSpaceType())
@test det_local_metric(EM, p, B) == one(eltype(p))
for M in [E, Ec, EH]
@test has_components(M)
p = [1.0, 2.0, 3.0]
q = [1.0, 2.0, 3.0]
X = [4.0, 5.0, 6.0]
for r in [1, 2, Inf]
@test norm(M, p, X, r) norm(X, r)
@test distance(M, p, q, r) norm(p - q, r)
end
end
@test log_local_metric_density(EM, p, B) == zero(eltype(p))
@test project!(E, p, p) == p
@test embed!(E, p, p) == p
Expand Down

0 comments on commit b3c0fa4

Please sign in to comment.