Skip to content

Commit

Permalink
Adapt to recent changes in ManifoldsBase 0.15 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Oct 15, 2023
1 parent 0b99b8e commit 600f46f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
40 changes: 31 additions & 9 deletions src/manifolds/PositiveNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 0 additions & 25 deletions src/manifolds/ProductManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
9 changes: 9 additions & 0 deletions test/manifolds/positive_numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 600f46f

Please sign in to comment.