Skip to content

Commit

Permalink
Allow copying scalars (#154)
Browse files Browse the repository at this point in the history
* Allow copying scalars

* minor change

* missing test
  • Loading branch information
mateuszbaran authored Apr 10, 2023
1 parent 57abbeb commit 3068619
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 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.14.3"
version = "0.14.4"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
10 changes: 8 additions & 2 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function check_size(M::AbstractManifold, p, X)
end

@doc raw"""
copy(M, p)
copy(M::AbstractManifold, 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.
Expand All @@ -273,9 +273,12 @@ function copy(M::AbstractManifold, p)
copyto!(M, q, p)
return q
end
function copy(::AbstractManifold, p::Number)
return copy(p)
end

@doc raw"""
copy(M, p, X)
copy(M::AbstractManifold, 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.
Expand All @@ -287,6 +290,9 @@ function copy(M::AbstractManifold, p, X)
copyto!(M, Y, p, X)
return Y
end
function copy(::AbstractManifold, p, X::Number)
return copy(X)
end


@doc raw"""
Expand Down
8 changes: 8 additions & 0 deletions test/default_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,12 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),)
@testset "performance" begin
@allocated isapprox(M, SA[1, 2], SA[3, 4]) == 0
end

@testset "scalars" begin
M = DefaultManifold()
p = 1.0
X = 2.0
@test copy(M, p) === p
@test copy(M, p, X) === X
end
end

2 comments on commit 3068619

@mateuszbaran
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81354

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.4 -m "<description of version>" 30686192b7d59d36284a5e171b00e98b5e597d51
git push origin v0.14.4

Please sign in to comment.