Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Oct 11, 2023
1 parent baa79b1 commit 561b0b5
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 165 deletions.
3 changes: 2 additions & 1 deletion ext/ManifoldsTestExt/tests_general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ function test_manifold(
Test.@testset "tangent vector distributions" begin
for tvd in tvector_distributions
supp = Manifolds.support(tvd)
Test.@test supp isa Manifolds.FVectorSupport{<:TangentSpace{ℝ,typeof(M)}}
Test.@test supp isa
Manifolds.FVectorSupport{<:TangentSpace{number_system(M),typeof(M)}}
for _ in 1:10
randtv = rand(tvd)
atol = rand_tvector_atol_multiplier * find_eps(randtv)
Expand Down
2 changes: 1 addition & 1 deletion src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export AbstractDecoratorManifold
export IsIsometricEmbeddedManifold, IsEmbeddedManifold, IsEmbeddedSubmanifold
export IsDefaultMetric, IsDefaultConnection, IsMetricManifold, IsConnectionManifold
export ValidationManifold, ValidationMPoint, ValidationTVector, ValidationCoTVector
export CotangentBundle, CotangentSpace, FVector
export FiberBundle, CotangentBundle, CotangentSpace, FVector
export AbstractPowerManifold,
AbstractPowerRepresentation,
ArrayPowerRepresentation,
Expand Down
4 changes: 2 additions & 2 deletions src/atlases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ struct InducedBasis{𝔽,VST<:VectorSpaceType,TA<:AbstractAtlas,TI} <: AbstractB
end

"""
induced_basis(::AbstractManifold, A::AbstractAtlas, i, VST::VectorSpaceType = TangentSpace)
induced_basis(::AbstractManifold, A::AbstractAtlas, i, VST::VectorSpaceType = TangentSpaceType())
Get the basis induced by chart with index `i` from an [`AbstractAtlas`](@ref) `A` of vector
space of type `vs`. Returns an object of type [`InducedBasis`](@ref).
Expand Down Expand Up @@ -417,7 +417,7 @@ function dual_basis(
::Any,
B::InducedBasis{𝔽,CotangentSpaceType},
) where {𝔽}
return induced_basis(M, B.A, B.i, TangentSpace)
return induced_basis(M, B.A, B.i, TangentSpaceType())
end

function ManifoldsBase._get_coordinates(M::AbstractManifold, p, X, B::InducedBasis)
Expand Down
70 changes: 0 additions & 70 deletions src/manifolds/Fiber.jl
Original file line number Diff line number Diff line change
@@ -1,71 +1 @@

"""
BundleFibers(fiber::FiberType, M::AbstractManifold)
Type representing a family of fibers of a fiber bundle over `M`
with fiber of type `fiber`. In contrast with `FiberBundle`, operations
on `BundleFibers` expect point-like and fiber-like parts to be
passed separately instead of being bundled together. It can be thought of
as a representation of fibers from a fiber bundle but without
storing the point at which a fiber is attached (which is specified
separately in various functions).
"""
struct BundleFibers{TF<:FiberType,TM<:AbstractManifold}
fiber::TF
manifold::TM
end

"""
allocate_result(B::BundleFibers, f, x...)
Allocates an array for the result of function `f` that is
an element of the fiber space of type `B.fiber` on manifold `B.manifold`
and arguments `x...` for implementing the non-modifying operation
using the modifying operation.
"""
@inline function allocate_result(B::BundleFibers, f::TF, x...) where {TF}
if length(x) == 0
# TODO: this may be incorrect when point and tangent vector representation are
# different for the manifold but there is no easy and generic way around that
return allocate_result(B.manifold, f)
else
T = allocate_result_type(B, f, x)
return allocate(x[1], T)
end
end

"""
allocate_result_type(B::BundleFibers, f, args::NTuple{N,Any}) where N
Return type of element of the array that will represent the result of
function `f` for representing an operation with result in the fiber `fiber`
for manifold `M` on given arguments (passed at a tuple).
"""
@inline function allocate_result_type(
::BundleFibers,
f::TF,
args::NTuple{N,Any},
) where {TF,N}
return typeof(mapreduce(eti -> one(number_eltype(eti)), +, args))
end

base_manifold(B::BundleFibers) = base_manifold(B.manifold)

function fiber_dimension(B::BundleFibers)
return fiber_dimension(B.manifold, B.fiber)
end

function Base.show(io::IO, fiber::BundleFibers)
return print(io, "BundleFibers($(fiber.fiber), $(fiber.manifold))")
end

"""
zero_vector(B::BundleFibers, p)
Compute the zero vector from the vector space of type `B.fiber` at point `p`
from manifold `B.manifold`.
"""
function zero_vector(B::BundleFibers, p)
X = allocate_result(B, zero_vector, p)
return zero_vector!(B, X, p)
end
109 changes: 49 additions & 60 deletions src/manifolds/FiberBundle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@ struct FiberBundle{
} <: AbstractManifold{𝔽}
type::TF
manifold::TM
fiber::BundleFibers{TF,TM}
vector_transport::TVT
end

function FiberBundle(
fiber::TVS,
M::TM,
vtm::FiberBundleProductVectorTransport,
) where {TVS<:FiberType,TM<:AbstractManifold{𝔽}} where {𝔽}
return FiberBundle{𝔽,TVS,TM,typeof(vtm)}(fiber, M, BundleFibers(fiber, M), vtm)
end
function FiberBundle(fiber::FiberType, M::AbstractManifold)
vtmm = vector_bundle_transport(fiber, M)
vtbm = FiberBundleProductVectorTransport(vtmm, vtmm)
Expand Down Expand Up @@ -157,6 +149,16 @@ Return the manifold the [`FiberBundle`](@ref)s is build on.
"""
base_manifold(B::FiberBundle) = base_manifold(B.manifold)

@doc raw"""
bundle_transport_to(B::FiberBundle, p, X, q)
Given a fiber bundle ``B=F \mathcal M``, points ``p, q\in\mathcal M``, an element ``X`` of
the fiber over ``p``, transport ``X`` to fiber over ``q``.
Exact meaning of the operation depends on the fiber bundle, or may even be undefined.
"""
bundle_transport_to(B::FiberBundle, p, X, q)

"""
bundle_projection(B::FiberBundle, p)
Expand All @@ -167,40 +169,30 @@ of `p` is attached.
bundle_projection(B::FiberBundle, p) = submanifold_component(B.manifold, p, Val(1))

function get_basis(M::FiberBundle, p, B::AbstractBasis)
xp1 = submanifold_component(p, Val(1))
xp1, xp2 = submanifold_components(M, p)
base_basis = get_basis(M.manifold, xp1, B)
fiber_basis = get_basis(M.fiber, xp1, B)
F = Fiber(M.manifold, xp1, M.type)
fiber_basis = get_basis(F, xp2, B)
return CachedBasis(B, FiberBundleBasisData(base_basis, fiber_basis))
end
function get_basis(M::FiberBundle, p, B::CachedBasis)
return invoke(get_basis, Tuple{AbstractManifold,Any,CachedBasis}, M, p, B)
end

function get_basis(M::FiberBundle, p, B::DiagonalizingOrthonormalBasis)
xp1 = submanifold_component(p, Val(1))
bv1 = DiagonalizingOrthonormalBasis(submanifold_component(B.frame_direction, Val(1)))
b1 = get_basis(M.manifold, xp1, bv1)
bv2 = DiagonalizingOrthonormalBasis(submanifold_component(B.frame_direction, Val(2)))
b2 = get_basis(M.fiber, xp1, bv2)
return CachedBasis(B, FiberBundleBasisData(b1, b2))
end

function get_coordinates(M::FiberBundle, p, X, B::AbstractBasis)
px, Vx = submanifold_components(M.manifold, p)
VXM, VXF = submanifold_components(M.manifold, X)
n = manifold_dimension(M.manifold)
return vcat(
get_coordinates(M.manifold, px, VXM, B),
get_coordinates(M.fiber, px, VXF, B),
)
F = Fiber(M.manifold, xp1, M.type)
return vcat(get_coordinates(M.manifold, px, VXM, B), get_coordinates(F, Vx, VXF, B))
end

function get_coordinates!(M::FiberBundle, Y, p, X, B::AbstractBasis)
px, Vx = submanifold_components(M.manifold, p)
VXM, VXF = submanifold_components(M.manifold, X)
n = manifold_dimension(M.manifold)
get_coordinates!(M.manifold, view(Y, 1:n), px, VXM, B)
get_coordinates!(M.fiber, view(Y, (n + 1):length(Y)), px, VXF, B)
F = Fiber(M.manifold, px, M.type)
get_coordinates!(F, view(Y, (n + 1):length(Y)), Vx, VXF, B)
return Y
end

Expand All @@ -212,9 +204,10 @@ function get_coordinates(
) where {𝔽}
px, Vx = submanifold_components(M.manifold, p)
VXM, VXF = submanifold_components(M.manifold, X)
F = Fiber(M.manifold, xp1, M.type)
return vcat(
get_coordinates(M.manifold, px, VXM, B.data.base_basis),
get_coordinates(M.fiber, px, VXF, B.data.fiber_basis),
get_coordinates(F, Vx, VXF, B.data.fiber_basis),
)
end

Expand All @@ -228,16 +221,19 @@ function get_coordinates!(
px, Vx = submanifold_components(M.manifold, p)
VXM, VXF = submanifold_components(M.manifold, X)
n = manifold_dimension(M.manifold)
F = Fiber(M.manifold, xp1, M.type)
get_coordinates!(M.manifold, view(Y, 1:n), px, VXM, B.data.base_basis)
get_coordinates!(M.fiber, view(Y, (n + 1):length(Y)), px, VXF, B.data.fiber_basis)
get_coordinates!(F, view(Y, (n + 1):length(Y)), Vx, VXF, B.data.fiber_basis)
return Y
end

function get_vector!(M::FiberBundle, Y, p, X, B::AbstractBasis)
n = manifold_dimension(M.manifold)
xp1 = submanifold_component(p, Val(1))
get_vector!(M.manifold, submanifold_component(Y, Val(1)), xp1, X[1:n], B)
get_vector!(M.fiber, submanifold_component(Y, Val(2)), xp1, X[(n + 1):end], B)
xp1, xp2 = submanifold_components(M, p)
Yp1, Yp2 = submanifold_components(M, Y)
F = Fiber(M.manifold, xp1, M.type)
get_vector!(M.manifold, Yp1, xp1, X[1:n], B)
get_vector!(F, Yp2, xp2, X[(n + 1):end], B)
return Y
end

Expand All @@ -249,44 +245,30 @@ function get_vector!(
B::CachedBasis{𝔽,<:AbstractBasis{𝔽},<:FiberBundleBasisData},
) where {𝔽}
n = manifold_dimension(M.manifold)
xp1 = submanifold_component(p, Val(1))
get_vector!(
M.manifold,
submanifold_component(Y, Val(1)),
xp1,
X[1:n],
B.data.base_basis,
)
get_vector!(
M.fiber,
submanifold_component(Y, Val(2)),
xp1,
X[(n + 1):end],
B.data.fiber_basis,
)
xp1, xp2 = submanifold_components(M, p)
Yp1, Yp2 = submanifold_components(M, Y)
F = Fiber(M.manifold, M.type, xp1)
get_vector!(M.manifold, Yp1, xp1, X[1:n], B.data.base_basis)
get_vector!(F, Yp2, xp2, X[(n + 1):end], B.data.fiber_basis)
return Y
end

function get_vectors(M::BundleFibers, p, B::CachedBasis)
return get_vectors(M.manifold, p, B)
end

function _isapprox(B::FiberBundle, p, q; kwargs...)
xp, Vp = submanifold_components(B.manifold, p)
xq, Vq = submanifold_components(B.manifold, q)
return isapprox(B.manifold, xp, xq; kwargs...) &&
isapprox(FiberAtPoint(B.fiber, xp), Vp, Vq; kwargs...)
isapprox(Fiber(B.manifold, xp, B.type), Vp, Vq; kwargs...)
end
function _isapprox(B::FiberBundle, p, X, Y; kwargs...)
px, Vx = submanifold_components(B.manifold, p)
VXM, VXF = submanifold_components(B.manifold, X)
VYM, VYF = submanifold_components(B.manifold, Y)
return isapprox(B.manifold, VXM, VYM; kwargs...) &&
isapprox(FiberAtPoint(B.fiber, px), VXF, VYF; kwargs...)
isapprox(Fiber(B.manifold, px, B.type), Vx, VXF, VYF; kwargs...)
end

function manifold_dimension(B::FiberBundle)
return manifold_dimension(B.manifold) + fiber_dimension(B.fiber)
return manifold_dimension(B.manifold) + fiber_dimension(B.manifold, B.type)
end

function Random.rand!(M::FiberBundle, pX; vector_at=nothing)
Expand All @@ -296,11 +278,11 @@ function Random.rand!(rng::AbstractRNG, M::FiberBundle, pX; vector_at=nothing)
pXM, pXF = submanifold_components(M.manifold, pX)
if vector_at === nothing
rand!(rng, M.manifold, pXM)
rand!(rng, FiberAtPoint(M.fiber, pXM), pXF)
rand!(rng, Fiber(M.manifold, pXM, M.type), pXF)
else
vector_atM, vector_atF = submanifold_components(M.manifold, vector_at)
rand!(rng, M.manifold, pXM; vector_at=vector_atM)
rand!(rng, FiberAtPoint(M.fiber, pXM), pXF; vector_at=vector_atF)
rand!(rng, Fiber(M.manifold, pXM, M.type), pXF; vector_at=vector_atF)
end
return pX
end
Expand Down Expand Up @@ -339,10 +321,11 @@ end

function get_vector(M::FiberBundle, p, X, B::AbstractBasis)
n = manifold_dimension(M.manifold)
xp1 = submanifold_component(p, Val(1))
xp1, xp2 = submanifold_components(M, p)
F = Fiber(M.manifold, xp1, M.type)
return ArrayPartition(
get_vector(M.manifold, xp1, X[1:n], B),
get_vector(M.fiber, xp1, X[(n + 1):end], B),
get_vector(F, xp2, X[(n + 1):end], B),
)
end
function get_vector(
Expand All @@ -352,10 +335,11 @@ function get_vector(
B::CachedBasis{𝔽,<:AbstractBasis{𝔽},<:FiberBundleBasisData},
) where {𝔽}
n = manifold_dimension(M.manifold)
xp1 = submanifold_component(p, Val(1))
xp1, xp2 = submanifold_components(M, p)
F = Fiber(M.manifold, M.type, xp1)
return ArrayPartition(
get_vector(M.manifold, xp1, X[1:n], B.data.base_basis),
get_vector(M.fiber, xp1, X[(n + 1):end], B.data.fiber_basis),
get_vector(F, xp2, X[(n + 1):end], B.data.fiber_basis),
)
end

Expand All @@ -364,14 +348,15 @@ function get_vectors(
p::ArrayPartition,
B::CachedBasis{𝔽,<:AbstractBasis{𝔽},<:FiberBundleBasisData},
) where {𝔽}
xp1 = submanifold_component(p, Val(1))
xp1, xp2 = submanifold_components(M, p)
zero_m = zero_vector(M.manifold, xp1)
zero_f = zero_vector(M.fiber, xp1)
vs = typeof(ArrayPartition(zero_m, zero_f))[]
F = Fiber(M.manifold, M.type, xp1)
for bv in get_vectors(M.manifold, xp1, B.data.base_basis)
push!(vs, ArrayPartition(bv, zero_f))
end
for bv in get_vectors(M.fiber, xp1, B.data.fiber_basis)
for bv in get_vectors(F, xp2, B.data.fiber_basis)
push!(vs, ArrayPartition(zero_m, bv))
end
return vs
Expand Down Expand Up @@ -413,6 +398,10 @@ component, respectively.
end
end

function Base.show(io::IO, B::FiberBundle)
return print(io, "FiberBundle($(B.type), $(B.manifold), $(B.vector_transport))")
end

@inline function Base.view(x::ArrayPartition, M::FiberBundle, s::Symbol)
(s === :point) && return x.x[1]
(s === :vector || s === :fiber) && return x.x[2]
Expand Down
19 changes: 5 additions & 14 deletions src/manifolds/VectorBundle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function CotangentBundle(M::AbstractManifold, vtm::FiberBundleProductVectorTrans
return VectorBundle(CotangentSpaceType(), M, vtm)
end

function bundle_transport_to!(B::TangentBundle, Y, p, X, q)
return vector_transport_to!(B.manifold, Y, p, X, q, B.vector_transport.method_fiber)
end

function default_inverse_retraction_method(::TangentBundle)
return FiberBundleInverseProductRetraction()
end
Expand Down Expand Up @@ -146,7 +150,7 @@ function inverse_retract_product!(B::VectorBundle, X, p, q)
py, Vy = submanifold_components(B.manifold, q)
VXM, VXF = submanifold_components(B.manifold, X)
log!(B.manifold, VXM, px, py)
vector_transport_to!(B.fiber, VXF, py, Vy, px, B.vector_transport.method_fiber)
bundle_transport_to!(B, VXF, py, Vy, px)
copyto!(VXF, VXF - Vx)
return X
end
Expand Down Expand Up @@ -212,16 +216,6 @@ function project!(B::VectorBundle, Y, p, X)
return Y
end

"""
project(B::BundleFibers, p, X)
Project vector `X` from the vector space of type `B.fiber` at point `p`.
"""
function project(B::BundleFibers, p, X)
Y = allocate_result(B, project, p, X)
return project!(B, Y, p, X)
end

function _retract(M::VectorBundle, p, X, t::Number, ::FiberBundleProductRetraction)
return retract_product(M, p, X, t)
end
Expand Down Expand Up @@ -296,9 +290,6 @@ function retract_sasaki!(B::TangentBundle, q, p, X, t::Number, m::SasakiRetracti
return q
end

function Base.show(io::IO, vb::VectorBundle)
return print(io, "VectorBundle($(vb.type.fiber), $(vb.manifold))")
end
Base.show(io::IO, vb::TangentBundle) = print(io, "TangentBundle($(vb.manifold))")

function vector_transport_direction(M::VectorBundle, p, X, d)
Expand Down
Loading

0 comments on commit 561b0b5

Please sign in to comment.