Skip to content

Commit

Permalink
add default_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Jul 18, 2024
1 parent e62fb72 commit 67d5511
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Function `allocate_as` to generically allocate point and tangent vectors on a manifold without a pre-existing instance but of a particular type.
* Function `default_type` to get the default type of points and tangent vectors for a manifold.

## [0.15.10] 19/05/2024

Expand Down
16 changes: 16 additions & 0 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@ function at the level, where also information from `p` and `M` can be accessed.
"""
copyto!(::AbstractManifold, Y, p, X) = copyto!(Y, X)

"""
default_type(M::AbstractManifold)
Get the default type of points on manifold `M`.
"""
default_type(M::AbstractManifold) = typeof(allocate_as(M))
"""
default_type(M::AbstractManifold, ft::FiberType)
Get the default type of points from the fiber `ft` of the fiber bundle based on manifold `M`.
For example, call `default_type(MyManifold(), TangentSpaceType())` to get the default type
of a tangent vector.
"""
default_type(M::AbstractManifold, ft::FiberType) = typeof(allocate_as(M, ft))

Check warning on line 423 in src/ManifoldsBase.jl

View check run for this annotation

Codecov / codecov/patch

src/ManifoldsBase.jl#L423

Added line #L423 was not covered by tests

@doc raw"""
distance(M::AbstractManifold, p, q)
Expand Down Expand Up @@ -1293,6 +1308,7 @@ export ×,
default_approximation_method,
default_inverse_retraction_method,
default_retraction_method,
default_type,
default_vector_transport_method,
distance,
exp,
Expand Down
2 changes: 2 additions & 0 deletions test/allocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ ManifoldsBase.representation_size(::AllocManifold3) = (2, 3)
an = allocate_as(M2, TangentSpaceType(), Array{Float32})
@test an isa Matrix{Float32}
@test size(an) == representation_size(M2)

@test default_type(M2) === Matrix{Float64}
end

0 comments on commit 67d5511

Please sign in to comment.