Skip to content

Commit

Permalink
Merge branch 'master' into matrixgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
sethaxen committed Nov 15, 2020
2 parents 7b9b200 + 3ffe741 commit d9bb56e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Manifolds"
uuid = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"]
version = "0.4.4"
version = "0.4.6"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
38 changes: 27 additions & 11 deletions src/groups/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Abstract type for a Lie group, a group that is also a smooth manifold with an
implement at least [`inv`](@ref), [`identity`](@ref), [`compose`](@ref), and
[`translate_diff`](@ref).
"""
abstract type AbstractGroupManifold{𝔽,O<:AbstractGroupOperation} <:
AbstractDecoratorManifold{𝔽} end
abstract type AbstractGroupManifold{𝔽,O<:AbstractGroupOperation,T<:AbstractEmbeddingType} <:
AbstractEmbeddedManifold{𝔽,T} end

"""
GroupManifold{𝔽,M<:Manifold{𝔽},O<:AbstractGroupOperation} <: AbstractGroupManifold{𝔽,O}
Expand All @@ -45,7 +45,7 @@ Group manifolds by default forward metric-related operations to the wrapped mani
GroupManifold(manifold, op)
"""
struct GroupManifold{𝔽,M<:Manifold{𝔽},O<:AbstractGroupOperation} <:
AbstractGroupManifold{𝔽,O}
AbstractGroupManifold{𝔽,O,TransparentIsometricEmbedding}
manifold::M
op::O
end
Expand All @@ -67,11 +67,13 @@ function base_group(M::Manifold)
end
base_group(G::AbstractGroupManifold) = G

decorator_group_dispatch(M::Manifold) = Val(false)
base_manifold(G::GroupManifold) = G.manifold

decorator_group_dispatch(::Manifold) = Val(false)
function decorator_group_dispatch(M::AbstractDecoratorManifold)
return decorator_group_dispatch(decorated_manifold(M))
end
decorator_group_dispatch(M::AbstractGroupManifold) = Val(true)
decorator_group_dispatch(::AbstractGroupManifold) = Val(true)

function is_group_decorator(M::Manifold)
return _extract_val(decorator_group_dispatch(M))
Expand All @@ -85,6 +87,22 @@ if VERSION ≥ v"1.3"
(::Type{T})(M::Manifold) where {T<:AbstractGroupOperation} = GroupManifold(M, T())
end

function decorator_transparent_dispatch(
::typeof(get_coordinates!),
::AbstractGroupManifold,
args...,
)
return Val(:transparent)
end
function decorator_transparent_dispatch(
::typeof(get_vector!),
::AbstractGroupManifold,
args...,
)
return Val(:transparent)
end


###################
# Action directions
###################
Expand Down Expand Up @@ -322,14 +340,12 @@ for MT in GROUP_MANIFOLD_BASIS_DISAMBIGUATION
)
end

@decorator_transparent_fallback :transparent function check_manifold_point(
G::AbstractGroupManifold,
e::Identity;
kwargs...,
)
manifold_dimension(G::GroupManifold) = manifold_dimension(G.manifold)

function check_manifold_point(G::AbstractGroupManifold, e::Identity; kwargs...)
return DomainError(e, "The identity element $(e) does not belong to $(G).")
end
@decorator_transparent_fallback :transparent function check_manifold_point(
function check_manifold_point(
G::GT,
e::Identity{GT};
kwargs...,
Expand Down
5 changes: 4 additions & 1 deletion src/manifolds/Rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ function check_manifold_point(M::Rotations{N}, p; kwargs...) where {N}
return DomainError(det(p), "The determinant of $p has to be +1 but it is $(det(p))")
end
if !isapprox(transpose(p) * p, one(p); kwargs...)
return DomainError(norm(p), "$p has to be orthogonal but it's not")
return DomainError(
norm(transpose(p) * p - one(p)),
"$p must be orthogonal but it's not at kwargs $kwargs",
)
end
return nothing
end
Expand Down
3 changes: 1 addition & 2 deletions src/manifolds/VectorBundle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,7 @@ function `f` for representing an operation with result in the vector space `fibe
for manifold `M` on given arguments (passed at a tuple).
"""
function allocate_result_type(::VectorBundleFibers, f, args::NTuple{N,Any}) where {N}
T = typeof(reduce(+, one(number_eltype(eti)) for eti in args))
return T
return typeof(mapreduce(eti -> one(number_eltype(eti)), +, args))
end

Base.size(x::FVector) = size(x.data)
Expand Down
3 changes: 2 additions & 1 deletion src/product_representations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ function Base.:*(
return ProductArray(ShapeSpec, a * v.data, v.reshapers)
end

number_eltype(::Type{ProductArray{TM,TData,TV}}) where {TM,TData,TV} = eltype(TData)
number_eltype(a::ProductArray) = number_eltype(a.data)
number_eltype(::Type{TPA}) where {TM,TData,TPA<:ProductArray{TM,TData}} = eltype(TData)

function _show_component(io::IO, v; pre = "", head = "")
sx = sprint(show, "text/plain", v, context = io, sizehint = 0)
Expand Down
2 changes: 1 addition & 1 deletion test/groups/special_orthogonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ include("group_utils.jl")
inverse_retraction_methods = inverse_retraction_methods,
exp_log_atol_multiplier = 20,
retraction_atol_multiplier = 12,
is_tangent_atol_multiplier = 1,
is_tangent_atol_multiplier = 1.2,
)

@test injectivity_radius(G) == injectivity_radius(M)
Expand Down
16 changes: 16 additions & 0 deletions test/product_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ include("utils.jl")

struct NotImplementedReshaper <: Manifolds.AbstractReshaper end

function parray(M, x)
return Manifolds.ProductArray(
Manifolds.ShapeSpecification(Manifolds.StaticReshaper(), M.manifolds...),
x,
)
end

@testset "Product manifold" begin
@test_throws MethodError ProductManifold()
M1 = Sphere(2)
Expand Down Expand Up @@ -422,6 +429,15 @@ struct NotImplementedReshaper <: Manifolds.AbstractReshaper end
@test submanifold_component(pts[1], Val(1)) === pts[1].parts[1]
@test submanifold_components(Mse, pts[1]) === pts[1].parts
@test submanifold_components(pts[1]) === pts[1].parts

p_inf = parray(Mse, randn(5))
@test (@inferred ManifoldsBase.allocate_result_type(
Mse,
Manifolds.log,
(p_inf, p_inf),
)) === Float64
@test (@inferred number_eltype(typeof(p_inf))) === Float64
@test pts_prod[1] .+ fill(1.0, 5) == pts_prod[1] .+ 1.0
end

@testset "ProductRepr" begin
Expand Down

0 comments on commit d9bb56e

Please sign in to comment.