From 600f46f4bf93715e4eb167fada84b6c4cbb6d4eb Mon Sep 17 00:00:00 2001 From: Mateusz Baran Date: Sun, 15 Oct 2023 11:39:49 +0200 Subject: [PATCH] Adapt to recent changes in ManifoldsBase 0.15 WIP --- src/manifolds/PositiveNumbers.jl | 40 +++++++++++++++++++++++------- src/manifolds/ProductManifold.jl | 25 ------------------- test/manifolds/positive_numbers.jl | 9 +++++++ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/manifolds/PositiveNumbers.jl b/src/manifolds/PositiveNumbers.jl index 81267c86a4..84313f329c 100644 --- a/src/manifolds/PositiveNumbers.jl +++ b/src/manifolds/PositiveNumbers.jl @@ -15,28 +15,40 @@ please use [`SymmetricPositiveDefinite`](@ref)`(1)`. struct PositiveNumbers <: AbstractManifold{ℝ} end """ - PositiveVectors(n) + PositiveVectors(n::Integer; parameter::Symbol=:type) Generate the manifold of vectors with positive entries. This manifold is modeled as a [`PowerManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/manifolds.html#ManifoldsBase.PowerManifold) of [`PositiveNumbers`](@ref). + +`parameter`: whether a type parameter should be used to store `n`. By default size +is stored in a type parameter. Value can either be `:field` or `:type`. """ -PositiveVectors(n::Integer) = PositiveNumbers()^n +PositiveVectors(n::Integer; parameter::Symbol=:type) = + PowerManifold(PositiveNumbers(), n; parameter=parameter) """ - PositiveMatrices(m,n) + PositiveMatrices(m::Integer, n::Integer; parameter::Symbol=:type) Generate the manifold of matrices with positive entries. This manifold is modeled as a [`PowerManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/manifolds.html#ManifoldsBase.PowerManifold) of [`PositiveNumbers`](@ref). + +`parameter`: whether a type parameter should be used to store `n`. By default size +is stored in a type parameter. Value can either be `:field` or `:type`. """ -PositiveMatrices(n::Integer, m::Integer) = PositiveNumbers()^(n, m) +PositiveMatrices(n::Integer, m::Integer; parameter::Symbol=:type) = + PowerManifold(PositiveNumbers(), n, m; parameter=parameter) """ - PositiveArrays(n₁,n₂,...,nᵢ) + PositiveArrays(n₁, n₂, ..., nᵢ; parameter::Symbol=:type) Generate the manifold of `i`-dimensional arrays with positive entries. This manifold is modeled as a [`PowerManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/manifolds.html#ManifoldsBase.PowerManifold) of [`PositiveNumbers`](@ref). + +`parameter`: whether a type parameter should be used to store `n`. By default size +is stored in a type parameter. Value can either be `:field` or `:type`. """ -PositiveArrays(n::Vararg{Int,I}) where {I} = PositiveNumbers()^(n) +PositiveArrays(n::Vararg{Int,I}; parameter::Symbol=:type) where {I} = + PowerManifold(PositiveNumbers(), n...; parameter=parameter) @doc raw""" change_representer(M::PositiveNumbers, E::EuclideanMetric, p, X) @@ -267,13 +279,23 @@ Base.show(io::IO, ::PositiveNumbers) = print(io, "PositiveNumbers()") function Base.show( io::IO, - ::PowerManifold{ℝ,PositiveNumbers,TSize,ArrayPowerRepresentation}, -) where {TSize} - s = [TSize.parameters...] + M::PowerManifold{ℝ,PositiveNumbers,TSize,ArrayPowerRepresentation}, +) where {TSize<:TypeParameter} + s = get_parameter(M.size) (length(s) == 1) && return print(io, "PositiveVectors($(s[1]))") (length(s) == 2) && return print(io, "PositiveMatrices($(s[1]), $(s[2]))") return print(io, "PositiveArrays($(join(s, ", ")))") end +function Base.show( + io::IO, + M::PowerManifold{ℝ,PositiveNumbers,TSize,ArrayPowerRepresentation}, +) where {TSize<:Tuple} + s = get_parameter(M.size) + (length(s) == 1) && return print(io, "PositiveVectors($(s[1]); parameter=:field)") + (length(s) == 2) && + return print(io, "PositiveMatrices($(s[1]), $(s[2]); parameter=:field)") + return print(io, "PositiveArrays($(join(s, ", ")); parameter=:field)") +end @doc raw""" parallel_transport_to(M::PositiveNumbers, p, X, q) diff --git a/src/manifolds/ProductManifold.jl b/src/manifolds/ProductManifold.jl index 14321356a2..275010f9b9 100644 --- a/src/manifolds/ProductManifold.jl +++ b/src/manifolds/ProductManifold.jl @@ -70,31 +70,6 @@ function adjoint_Jacobi_field!(M::ProductManifold, Y, p, q, t, X, β::Tβ) where return Y end -@doc raw""" - cross(M, N) - cross(M1, M2, M3,...) - -Return the [`ProductManifold`](@ref) For two `AbstractManifold`s `M` and `N`, -where for the case that one of them is a [`ProductManifold`](@ref) itself, -the other is either prepended (if `N` is a product) or appenden (if `M`) is. -If both are product manifold, they are combined into one product manifold, -keeping the order. - -For the case that more than one is a product manifold of these is build with the -same approach as above -""" -cross(::AbstractManifold...) -LinearAlgebra.cross(M1::AbstractManifold, M2::AbstractManifold) = ProductManifold(M1, M2) -function LinearAlgebra.cross(M1::ProductManifold, M2::AbstractManifold) - return ProductManifold(M1.manifolds..., M2) -end -function LinearAlgebra.cross(M1::AbstractManifold, M2::ProductManifold) - return ProductManifold(M1, M2.manifolds...) -end -function LinearAlgebra.cross(M1::ProductManifold, M2::ProductManifold) - return ProductManifold(M1.manifolds..., M2.manifolds...) -end - @doc raw""" flat(M::ProductManifold, p, X::FVector{TangentSpaceType}) diff --git a/test/manifolds/positive_numbers.jl b/test/manifolds/positive_numbers.jl index 3aec6d5868..65687159b6 100644 --- a/test/manifolds/positive_numbers.jl +++ b/test/manifolds/positive_numbers.jl @@ -102,4 +102,13 @@ include("../utils.jl") rand!(M, X; vector_at=p) @test is_vector(M, p, X) end + + @testset "field parameter" begin + M1 = PositiveVectors(3; parameter=:field) + @test repr(M1) == "PositiveVectors(3; parameter=:field)" + M2 = PositiveMatrices(3, 4; parameter=:field) + @test repr(M2) == "PositiveMatrices(3, 4; parameter=:field)" + M3 = PositiveArrays(3, 4, 5; parameter=:field) + @test repr(M3) == "PositiveArrays(3, 4, 5; parameter=:field)" + end end