Skip to content

Commit

Permalink
Add element access for power and product tangent spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer committed May 18, 2024
1 parent e760dc5 commit 7c9a692
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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] unreleased

* 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

### Added
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ManifoldsBase"
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"]
version = "0.15.9"
version = "0.15.10"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
1 change: 1 addition & 0 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ export ×,
allocate,
angle,
base_manifold,
base_point,
change_basis,
change_basis!,
change_metric,
Expand Down
17 changes: 17 additions & 0 deletions src/PowerManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,23 @@ 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 a [`AbstractPowerManifold`](@ref)s tangent space `TpM`.
"""
function Base.getindex(

Check warning on line 787 in src/PowerManifold.jl

View check run for this annotation

Codecov / codecov/patch

src/PowerManifold.jl#L787

Added line #L787 was not covered by tests
TpM::TangentSpace{𝔽,<:AbstractPowerManifold},
I::Union{Integer,Colon,AbstractVector}...,
) where {𝔽}
M = base_manifold(TpM).manifold
p = base_point(TpM)[base_manifold(TpM), I]
return TangentSpace(M, p)

Check warning on line 793 in src/PowerManifold.jl

View check run for this annotation

Codecov / codecov/patch

src/PowerManifold.jl#L791-L793

Added lines #L791 - L793 were not covered by tests
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)
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"""
bae_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
9 changes: 9 additions & 0 deletions test/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,13 @@ struct TestArrayRepresentation <: AbstractPowerRepresentation end
p = rand(N)
@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 = TangentSpace(M, p[N, 1])
@test base_point(Tp1M) === p[1]
end
end
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

0 comments on commit 7c9a692

Please sign in to comment.