Skip to content

Commit

Permalink
Merge c534f94 into 516a43e
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer authored Jun 27, 2021
2 parents 516a43e + c534f94 commit ca1aee4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
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.12.1"
version = "0.12.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
35 changes: 32 additions & 3 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Base:
exp,
log,
convert,
copy,
copyto!,
angle,
eltype,
Expand Down Expand Up @@ -81,7 +82,7 @@ end
Return type of element of the array that will represent the result of function `f` and the
[`AbstractManifold`](@ref) `M` on given arguments `args` (passed as a tuple).
"""
function allocate_result_type(M::AbstractManifold, f, args::NTuple{N,Any}) where {N}
function allocate_result_type(::AbstractManifold, f, args::NTuple{N,Any}) where {N}
return typeof(mapreduce(eti -> one(number_eltype(eti)), +, args))
end

Expand Down Expand Up @@ -175,6 +176,33 @@ function check_size(M::AbstractManifold, p, X)
end
end

@doc raw"""
copy(M, p)
Copy the value(s) from the point `p` on the [`AbstractManifold`](@ref) `M` into a new point.
See [`allocate_result`](@ref) for the allocation of new point memory and [`copyto!`](@ref) for the copying.
"""
function copy(M::AbstractManifold, p)
q = allocate_result(M, copy, p)
copyto!(M, q, p)
return q
end

@doc raw"""
copy(M, p, X)
Copy the value(s) from the tangent vector `X` at a point `p` on the
[`AbstractManifold`](@ref) `M` into a new tangent vector.
See [`allocate_result`](@ref) for the allocation of new point memory and [`copyto!`](@ref) for the copying.
"""
function copy(M::AbstractManifold, p, X)
# the order of args switched, since the allocation by default takes the type of the first.
Y = allocate_result(M, copy, X, p)
copyto!(M, Y, p, X)
return Y
end


@doc raw"""
copyto!(M::AbstractManifold, q, p)
Expand Down Expand Up @@ -272,8 +300,7 @@ see [`AbstractEmbeddedManifold`](@ref) how you can avoid reimplementing code fro
See also: [`EmbeddedManifold`](@ref), [`project`](@ref project(M::AbstractManifold, p, X))
"""
function embed(M::AbstractManifold, p, X)
# Note that the order is switched,
# since the allocation by default takes the type of the first.
# the order of args switched, since the allocation by default takes the type of the first.
Y = allocate_result(M, embed, X, p)
embed!(M, Y, p, X)
return Y
Expand Down Expand Up @@ -596,6 +623,8 @@ export allocate,
check_point,
check_vector,
check_size,
copy,
copyto!,
distance,
exp,
exp!,
Expand Down
16 changes: 16 additions & 0 deletions test/default_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,20 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),)
a = NLsolveInverseRetraction(ExponentialRetraction())
@test a.retraction isa ExponentialRetraction
end

@testset "copy of points and vectors" begin
M = DefaultManifold(2)
p = [2.0, 3.0]
q = similar(p)
copyto!(M, q, p)
@test p == q
r = copy(M, p)
@test r == p
X = [4.0, 5.0]
Y = similar(X)
copyto!(M, Y, p, X)
@test Y == X
Z = copy(M, p, X)
@test Z == X
end
end

0 comments on commit ca1aee4

Please sign in to comment.