Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TpM[i] for power/product manifolds #191

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading