Skip to content

Commit 0106e09

Browse files
committed
Move ZeroVector to tangent_space, reduce to the methods that do not cause ambiguities. Document this carefully.
1 parent 944f362 commit 0106e09

4 files changed

Lines changed: 44 additions & 177 deletions

File tree

docs/src/manifolds.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ helpers to build or create manifolds based on existing manifolds
55

66
## A default manifold
77

8-
[`DefaultManifold`](@ref ManifoldsBase.DefaultManifold) is a simplified version of [`Euclidean`](https://juliamanifolds.github.io/Manifolds.jl/latest/manifolds/euclidean.html) and demonstrates a basic interface implementation.
8+
[`DefaultManifold`](@ref ManifoldsBase.DefaultManifold) is a simplified version of [`Euclidean`](@extref `Manifolds.Euclidean`) and demonstrates a basic interface implementation.
99
It can be used to perform simple tests.
10-
Since when using `Manifolds.jl` the [`Euclidean`](https://juliamanifolds.github.io/Manifolds.jl/latest/manifolds/euclidean.html) is available, the `DefaultManifold` itself is not exported.
10+
Since when using `Manifolds.jl` the [`Euclidean`](@extref `Manifolds.Euclidean`) is available, the [`DefaultManifold`](@ref ManifoldsBase.DefaultManifold) itself is not exported.
1111

1212
```@docs
1313
ManifoldsBase.DefaultManifold

src/ManifoldsBase.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,7 @@ function zero_vector(M::AbstractManifold, p)
12141214
return X
12151215
end
12161216

1217+
12171218
#
12181219
#
12191220
# Internal function to set plotting backend
@@ -1260,8 +1261,6 @@ include("nested_trait.jl")
12601261
include("connection.jl")
12611262
include("metric.jl")
12621263

1263-
include("zero_vector.jl")
1264-
12651264
include("decorator_trait.jl")
12661265
include("numerical_checks.jl")
12671266

src/vector_spaces.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,44 @@ manifold.
102102
"""
103103
const AbstractCotangentVector = AbstractFibreVector{CotangentSpaceType}
104104

105+
106+
"""
107+
ZeroVector <: AbstractTangentVector
108+
109+
A type to represent the zero vector. This can be used generically
110+
when it is beneficial to not allocate memory in certain places of computations.
111+
112+
!!! note "Technical Note"
113+
Following our [Design principles](design.md) the dispatch on tangent vectors
114+
only happens on the most inner (third) layer, providing generic implementations
115+
with this type is a very manifold-specific task and should be considered carefully.
116+
117+
Therefore there are also only a few generic implementations available, e.g. [`zero_vector`](@ref zero_vector(::AbstractManifold, ::Any, ::Bool))
118+
"""
119+
struct ZeroVector <: AbstractTangentVector end
120+
105121
Base.:+(X::FVector, Y::FVector) = FVector(X.type, X.data + Y.data, X.basis)
122+
Base.:+(::ZeroVector, Y) = Y
123+
Base.:+(X, ::ZeroVector) = X
124+
Base.:+(::ZeroVector, ::ZeroVector) = ZeroVector()
125+
106126

107127
Base.:-(X::FVector, Y::FVector) = FVector(X.type, X.data - Y.data, X.basis)
128+
Base.:-(::ZeroVector, Y) = -Y
129+
Base.:-(X, ::ZeroVector) = X
130+
Base.:-(::ZeroVector, ::ZeroVector) = ZeroVector()
131+
108132
Base.:-(X::FVector) = FVector(X.type, -X.data, X.basis)
133+
Base.:-(::ZeroVector) = ZeroVector()
109134

110135
Base.:*(a::Number, X::FVector) = FVector(X.type, a * X.data, X.basis)
136+
Base.:*(::Number, ::ZeroVector) = ZeroVector()
111137

112138
allocate(x::FVector) = FVector(x.type, allocate(x.data), x.basis)
113139
allocate(x::FVector, ::Type{T}) where {T} = FVector(x.type, allocate(x.data, T), x.basis)
140+
allocate(::ZeroVector) = ZeroVector()
141+
142+
copy(::AbstractManifold, p, ::ZeroVector) = ZeroVector()
114143

115144
function Base.copyto!(X::FVector, Y::FVector)
116145
copyto!(X.data, Y.data)
@@ -134,3 +163,15 @@ vector_space_dimension(::AbstractManifold, ::VectorSpaceType)
134163
function vector_space_dimension(M::AbstractManifold, ::TCoTSpaceType)
135164
return manifold_dimension(M)
136165
end
166+
167+
@doc raw"""
168+
zero_vector(M::AbstractManifold, p, allocate::Bool = true)
169+
170+
Return the tangent vector from the tangent space ``T_p\mathcal M`` at `p` on the
171+
[`AbstractManifold`](@ref) `M`, that represents the zero vector.
172+
Setting `allocate = false` avoids allocation of memory for this vector
173+
and returns a [`ZeroVector`](@ref)`()`.
174+
"""
175+
function zero_vector(M::AbstractManifold, p, allocate::Bool)
176+
return allocate ? zero_vector(M, p) : ZeroVector()
177+
end

src/zero_vector.jl

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)