From 7d05dc2d8d3dce57b14f10f17d12baf83460ec35 Mon Sep 17 00:00:00 2001 From: Ronny Bergmann Date: Fri, 22 Sep 2023 14:00:46 +0200 Subject: [PATCH 1/3] fix tangent vector allocations (nearly) --- src/ManifoldsBase.jl | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ManifoldsBase.jl b/src/ManifoldsBase.jl index d3d6e6c1..5c2e5325 100644 --- a/src/ManifoldsBase.jl +++ b/src/ManifoldsBase.jl @@ -854,21 +854,33 @@ Optionally a random number generator `rng` to be used can be specified. An optio """ Random.rand(M::AbstractManifold) + +# unresolvable ambiguity but this would be nice to have +#allocate_result(M::AbstractManifold, ::typeof(rand), p) = zero_vector(M, p) + function Random.rand(M::AbstractManifold, d::Integer; kwargs...) return [rand(M; kwargs...) for _ in 1:d] end function Random.rand(rng::AbstractRNG, M::AbstractManifold, d::Integer; kwargs...) return [rand(rng, M; kwargs...) for _ in 1:d] end -function Random.rand(M::AbstractManifold; kwargs...) - p = allocate_result(M, rand) - rand!(M, p; kwargs...) - return p +function Random.rand(M::AbstractManifold; vector_at = nothing, kwargs...) + if vector_at === nothing + pX = allocate_result(M, rand) + else + pX = allocate_result(M, rand, vector_at) + end + rand!(M, pX; vector_at = vector_at, kwargs...) + return pX end -function Random.rand(rng::AbstractRNG, M::AbstractManifold; kwargs...) - p = allocate_result(M, rand) - rand!(rng, M, p; kwargs...) - return p +function Random.rand(rng::AbstractRNG, M::AbstractManifold; vector_at = nothing, kwargs...) + if vector_at === nothing + pX = allocate_result(M, rand) + else + pX = allocate_result(M, rand, vector_at) + end + rand!(rng, M, pX; vector_at = vector_at, kwargs...) + return pX end @doc raw""" From caf850e370ad2abe35250dde7bb84929c4314778 Mon Sep 17 00:00:00 2001 From: Ronny Bergmann Date: Fri, 22 Sep 2023 14:08:02 +0200 Subject: [PATCH 2/3] Remove a method. --- src/ManifoldsBase.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ManifoldsBase.jl b/src/ManifoldsBase.jl index 5c2e5325..9296f1fc 100644 --- a/src/ManifoldsBase.jl +++ b/src/ManifoldsBase.jl @@ -855,9 +855,6 @@ Optionally a random number generator `rng` to be used can be specified. An optio """ Random.rand(M::AbstractManifold) -# unresolvable ambiguity but this would be nice to have -#allocate_result(M::AbstractManifold, ::typeof(rand), p) = zero_vector(M, p) - function Random.rand(M::AbstractManifold, d::Integer; kwargs...) return [rand(M; kwargs...) for _ in 1:d] end From ab8e4823edf6fc736348bdaae06ee7f1d79d8999 Mon Sep 17 00:00:00 2001 From: Ronny Bergmann Date: Fri, 22 Sep 2023 19:34:22 +0200 Subject: [PATCH 3/3] bump version. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c9f15b84..33e92c23 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ManifoldsBase" uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb" authors = ["Seth Axen ", "Mateusz Baran ", "Ronny Bergmann ", "Antoine Levitt "] -version = "0.14.11" +version = "0.14.12" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"