Skip to content

Commit

Permalink
Introduce TpM[i] for power/product manifolds (#191)
Browse files Browse the repository at this point in the history
* Add element access for power and product tangent spaces.
* Fix test coverage for power.
* Apply suggestions from code review
---------

Co-authored-by: Mateusz Baran <[email protected]>
  • Loading branch information
kellertuer and mateuszbaran authored May 19, 2024
1 parent 45ad6af commit 5fb1add
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.15.10] 15/05/2024
## [0.15.10] 19/05/2024

### Added

* Functions `fill(p, N)` and `fill!(P, p, N)` to fill values into a point on a power manifold `N`.
* introduce a `base_point(TpM)` to access the base point of a tangent space
* introduce `TpM[i]` to access tangent spaces of factors from an `AbstractPowerManifold` or a `ProductManifold`.


## [0.15.9] 02/05/2024

Expand Down
1 change: 1 addition & 0 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ export ×,
allocate,
angle,
base_manifold,
base_point,
change_basis,
change_basis!,
change_metric,
Expand Down
15 changes: 15 additions & 0 deletions src/PowerManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,21 @@ Base.@propagate_inbounds function Base.getindex(
return get_component(M, p, I...)
end

"""
getindex(M::TangentSpace{𝔽, AbstractPowerManifold}, i...)
TpM[i...]
Access the `i`th manifold component from an [`AbstractPowerManifold`](@ref)s' tangent space `TpM`.
"""
function Base.getindex(
TpM::TangentSpace{𝔽,<:AbstractPowerManifold},
I::Union{Integer,Colon,AbstractVector}...,
) where {𝔽}
M = base_manifold(TpM)
p = base_point(TpM)
return TangentSpace(M.manifold, p[M, I...])
end

@doc raw"""
injectivity_radius(M::AbstractPowerManifold[, p])
Expand Down
11 changes: 11 additions & 0 deletions src/ProductManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ access the `i`th manifold component from the [`ProductManifold`](@ref) `M`.
"""
@inline Base.getindex(M::ProductManifold, i::Integer) = M.manifolds[i]

"""
getindex(M::TangentSpace{𝔽,<:ProductManifold}, i::Integer)
TpM[i]
Access the `i`th manifold component from a [`ProductManifold`](@ref)s' tangent space `TpM`.
"""
function Base.getindex(TpM::TangentSpace{𝔽,<:ProductManifold}, i::Integer) where {𝔽}
M = base_manifold(TpM)
return TangentSpace(M[i], base_point(TpM)[M, i])
end

ProductManifold() = throw(MethodError("No method matching ProductManifold()."))

const PRODUCT_BASIS_LIST = [
Expand Down
7 changes: 7 additions & 0 deletions src/TangentSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ function allocate_result(M::TangentSpace, ::typeof(rand))
return zero_vector(M.manifold, M.point)
end

@doc raw"""
base_point(TpM::TangentSpace)
Return the base point of the [`TangentSpace`](@ref).
"""
base_point(TpM::TangentSpace) = TpM.point

# forward both point checks to tangent vector checks
function check_point(TpM::TangentSpace, p; kwargs...)
return check_vector(TpM.manifold, TpM.point, p; kwargs...)
Expand Down
14 changes: 12 additions & 2 deletions test/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ using Test
using ManifoldsBase
using ManifoldsBase:
AbstractNumbers,
DefaultManifold,
ℝ,
ℂ,
NestedReplacingPowerRepresentation,
VectorSpaceType
VectorSpaceType,
DefaultManifold
using StaticArrays
using LinearAlgebra
using Random
Expand Down Expand Up @@ -411,6 +411,16 @@ end
@test zero_vector(N, p) == 0 .* p
end

@testset "TangentSpace" begin
M = ManifoldsBase.DefaultManifold(3)
N = PowerManifold(M, NestedPowerRepresentation(), 2)
p = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
TpN = TangentSpace(N, p)
Tp1M = TpN[1]
@test base_point(Tp1M) === p[N, 1]
@test base_manifold(Tp1M) === M
end

@testset "fill" begin
M = ManifoldsBase.DefaultManifold(3)
N = PowerManifold(M, NestedPowerRepresentation(), 2)
Expand Down
8 changes: 7 additions & 1 deletion test/product_manifold.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using ManifoldsBase
using ManifoldsBase: submanifold_component, submanifold_components
using ManifoldsBase: DefaultManifold, submanifold_component, submanifold_components
using ManifoldsBase:
AbstractNumbers, ℝ, ℂ, NestedReplacingPowerRepresentation, ProductBasisData
using LinearAlgebra
Expand Down Expand Up @@ -606,4 +606,10 @@ using ManifoldsBaseTestUtils
@test ts1 × ts1 == ProductVectorTransport(tr1, tr2, tr1, tr2)
end

@testset "TangentSpace" begin
TpM = TangentSpace(M, p1)
Tp1M1 = TpM[1]
@test base_point(Tp1M1) === p1[M, 1]
@test base_manifold(Tp1M1) === M[1]
end
end

5 comments on commit 5fb1add

@kellertuer
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 register

Release notes:

Added

  • Functions fill(p, N) and fill!(P, p, N) to fill values into a point on a power manifold N.
  • introduce a base_point(TpM) to access the base point of a tangent space
  • introduce TpM[i] to access tangent spaces of factors from an AbstractPowerManifold or a ProductManifold.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Error while trying to register: Unexpected error in registration

@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/107172

Tagging

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.15.10 -m "<description of version>" 5fb1addbeee4561fce8d97b87856e695531b2525
git push origin v0.15.10

@kellertuer
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 register

Release notes:

Added

  • Functions fill(p, N) and fill!(P, p, N) to fill values into a point on a power manifold N.
  • introduce a base_point(TpM) to access the base point of a tangent space
  • introduce TpM[i] to access tangent spaces of factors from an AbstractPowerManifold or a ProductManifold.

@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 updated: JuliaRegistries/General/107172

Tagging

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.15.10 -m "<description of version>" 5fb1addbeee4561fce8d97b87856e695531b2525
git push origin v0.15.10

Please sign in to comment.