Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Sep 5, 2023
1 parent 0f8e431 commit f8961e7
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 323 deletions.
37 changes: 35 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,48 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.0]
## [0.9.0] - 2023-mm-dd

### Added

- Vector bundles are generalized to fiber bundles.
- `RotationTranslationAction`.
- `DirectSumType` for vector bundles: `MultitangentBundle`, `MultitangentBundleFibers`, `MultitangentSpaceAtPoint`.

### Changed

- Sizes of all manifolds can now be either encoded in type or stored in a field to avoid over-specialization.
The default is set to store the size in a field. To obtain the old behavior, pass the `parameter=:type` keyword
argument to manifold constructor. Related changes:
- `SpecialEuclidean{N}` renamed to `StaticSpecialEuclidean{N}`.
- Statically sized `SpecialEuclidean{N}` is now `SpecialEuclidean{TypeParameter{Tuple{N}}}`, whereas the type of special Euclidean group with field-stored size is `SpecialEuclidean{Tuple{Int}}`. Similar change applies to `GeneralUnitaryMultiplicationGroup{n}`, `Orthogonal{n}`, `SpecialOrthogonal{n}`, `SpecialUnitary{n}`, `SpecialEuclideanManifold{n}`, `TranslationGroup`. For example

```{julia}
function Base.show(io::IO, ::SpecialEuclidean{n}) where {n}
return print(io, "SpecialEuclidean($(n))")
end
```

needs to be replaced with

```{julia}
function Base.show(io::IO, ::SpecialEuclidean{TypeParameter{Tuple{n}}}) where {n}
return print(io, "SpecialEuclidean($(n); parameter=:type)")
end
```

for statically-sized groups and

```{julia}
function Base.show(io::IO, G::SpecialEuclidean{Tuple{Int}})
n = get_n(G)
return print(io, "SpecialEuclidean($(n))")
end
```

for groups with size stored in field.
- Argument order for type alias `RotationActionOnVector`: most often dispatched on argument is now first.

### Removed

- `ProductRepr` is removed; please use `ArrayPartition` instead.
- Default methods throwing "not implemented" `ErrorException` for some group-related operations.
30 changes: 5 additions & 25 deletions src/groups/group_action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ abstract type AbstractGroupAction{AD<:ActionDirection} end
The group that acts in action `A`.
"""
base_group(A::AbstractGroupAction) = error("base_group not implemented for $(typeof(A)).")
base_group(A::AbstractGroupAction)

"""
group_manifold(A::AbstractGroupAction)
The manifold the action `A` acts upon.
"""
function group_manifold(A::AbstractGroupAction)
return error("group_manifold not implemented for $(typeof(A)).")
end
group_manifold(A::AbstractGroupAction)

function allocate_result(A::AbstractGroupAction, f, p...)
return allocate_result(group_manifold(A), f, p...)
Expand Down Expand Up @@ -65,11 +63,7 @@ end
Apply action `a` to the point `p` with the rule specified by `A`.
The result is saved in `q`.
"""
function apply!(A::AbstractGroupAction{LeftForwardAction}, q, a, p)
return error(
"apply! not implemented for action $(typeof(A)) and points $(typeof(q)), $(typeof(p)) and $(typeof(a)).",
)
end
apply!(A::AbstractGroupAction, q, a, p)
function apply!(A::AbstractGroupAction{RightForwardAction}, q, a, p)
ainv = inv(base_group(A), a)
apply!(switch_direction(A, LeftRightSwitch()), q, ainv, p)
Expand Down Expand Up @@ -111,17 +105,7 @@ differential transports vectors
(\mathrm{d}τ_a)_p : T_p \mathcal M → T_{τ_a p} \mathcal M
````
"""
function apply_diff(A::AbstractGroupAction, a, p, X)
return error(
"apply_diff not implemented for action $(typeof(A)), points $(typeof(a)) and $(typeof(p)), and vector $(typeof(X))",
)
end

function apply_diff!(A::AbstractGroupAction, Y, a, p, X)
return error(
"apply_diff! not implemented for action $(typeof(A)), points $(typeof(a)) and $(typeof(p)), vectors $(typeof(Y)) and $(typeof(X))",
)
end
apply_diff(A::AbstractGroupAction, a, p, X)

@doc raw"""
apply_diff_group(A::AbstractGroupAction, a, X, p)
Expand Down Expand Up @@ -208,11 +192,7 @@ the element closest to `q` in the metric of the G-manifold:
```
where $\mathcal{G}$ is the group that acts on the G-manifold $\mathcal M$.
"""
function optimal_alignment(A::AbstractGroupAction, p, q)
return error(
"optimal_alignment not implemented for $(typeof(A)) and points $(typeof(p)) and $(typeof(q)).",
)
end
optimal_alignment(A::AbstractGroupAction, p, q)

"""
optimal_alignment!(A::AbstractGroupAction, x, p, q)
Expand Down
2 changes: 1 addition & 1 deletion src/groups/rotation_action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Base.show(io::IO, A::RotationAction)
end

const RotationActionOnVector{TAD,𝔽,TE,TSO} = RotationAction{
Euclidean{TE,𝔽},
<:Union{Euclidean{TE,𝔽},TranslationGroup{TE,𝔽}},
SpecialOrthogonal{TSO},
TAD,
} where {TAD<:ActionDirection,𝔽,TE,TSO}
Expand Down
30 changes: 21 additions & 9 deletions src/groups/special_euclidean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ const SpecialEuclidean{T} = SemidirectProductGroup{
const SpecialEuclideanManifold{N} =
ProductManifold{ℝ,Tuple{TranslationGroup{N,ℝ},SpecialOrthogonal{N}}}

function SpecialEuclidean(n; parameter::Symbol=:type)
function SpecialEuclidean(n; parameter::Symbol=:field)
Tn = TranslationGroup(n; parameter=parameter)
SOn = SpecialOrthogonal(n; parameter=parameter)
A = RotationAction(Tn, SOn)
return SemidirectProductGroup(Tn, SOn, A)
end

const SpecialEuclideanOperation{N} = SemidirectProductOperation{
RotationAction{TranslationGroup{Tuple{N},ℝ},SpecialOrthogonal{N},LeftForwardAction},
RotationAction{TranslationGroup{N,ℝ},SpecialOrthogonal{N},LeftForwardAction},
}
const SpecialEuclideanIdentity{N} = Identity{SpecialEuclideanOperation{N}}

function Base.show(io::IO, ::SpecialEuclidean{TypeParameter{Tuple{n}}}) where {n}
return print(io, "SpecialEuclidean($(n); field=:type)")
return print(io, "SpecialEuclidean($(n); parameter=:type)")
end
function Base.show(io::IO, G::SpecialEuclidean{Tuple{Int}})
n = get_n(G)
Expand All @@ -60,7 +60,9 @@ end
end

get_n(::SpecialEuclidean{TypeParameter{Tuple{N}}}) where {N} = N
get_n(M::SpecialEuclidean{Tuple{Int}}) = manifold_dimension(M.manifold.manifolds[1])
get_n(M::SpecialEuclidean{Tuple{Int}}) = get_n(M.manifold)
get_n(::SpecialEuclideanManifold{TypeParameter{Tuple{N}}}) where {N} = N
get_n(M::SpecialEuclideanManifold{Tuple{Int}}) = manifold_dimension(M.manifolds[1])

Base.@propagate_inbounds function Base.getindex(
p::AbstractMatrix,
Expand Down Expand Up @@ -121,7 +123,7 @@ Base.@propagate_inbounds function _padpoint!(
end

Base.@propagate_inbounds function _padvector!(
::Union{SpecialEuclidean,SpecialEuclideanManifold},
G::Union{SpecialEuclidean,SpecialEuclideanManifold},
X::AbstractMatrix,
)
n = get_n(G)
Expand All @@ -132,7 +134,7 @@ Base.@propagate_inbounds function _padvector!(
end

@doc raw"""
adjoint_action(::SpecialEuclidean{3}, p, fX::TFVector{<:Any,VeeOrthogonalBasis{ℝ}})
adjoint_action(::SpecialEuclidean{TypeParameter{Tuple{3}}}, p, fX::TFVector{<:Any,VeeOrthogonalBasis{ℝ}})
Adjoint action of the [`SpecialEuclidean`](@ref) group on the vector with coefficients `fX`
tangent at point `p`.
Expand All @@ -142,7 +144,11 @@ The formula for the coefficients reads ``t×(R⋅ω) + R⋅r`` for the translati
matrix part of `p`, `r` is the translation part of `fX` and `ω` is the rotation part of `fX`,
``×`` is the cross product and ``⋅`` is the matrix product.
"""
function adjoint_action(::SpecialEuclidean{3}, p, fX::TFVector{<:Any,VeeOrthogonalBasis{ℝ}})
function adjoint_action(
::SpecialEuclidean{TypeParameter{Tuple{3}}},
p,
fX::TFVector{<:Any,VeeOrthogonalBasis{ℝ}},
)
t, R = submanifold_components(p)
r = fX.data[SA[1, 2, 3]]
ω = fX.data[SA[4, 5, 6]]
Expand Down Expand Up @@ -178,12 +184,18 @@ function affine_matrix(G::SpecialEuclidean, p)
return pmat
end
affine_matrix(::SpecialEuclidean, p::AbstractMatrix) = p
function affine_matrix(::SpecialEuclidean{n}, ::SpecialEuclideanIdentity{n}) where {n}
function affine_matrix(
::SpecialEuclidean{TypeParameter{Tuple{n}}},
::SpecialEuclideanIdentity{TypeParameter{Tuple{n}}},
) where {n}
s = maybesize(Size(n, n))
s isa Size && return SDiagonal{n,Float64}(I)
return Diagonal{Float64}(I, n)
end
function affine_matrix(::SpecialEuclidean{Tuple{Int}}, ::SpecialEuclideanIdentity)
function affine_matrix(
G::SpecialEuclidean{Tuple{Int}},
::SpecialEuclideanIdentity{Tuple{Int}},
)
n = get_n(G)
return Diagonal{Float64}(I, n)
end
Expand Down
2 changes: 1 addition & 1 deletion src/manifolds/GeneralUnitaryMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function get_vector_orthogonal!(
return X .= 0
end
function get_vector_orthogonal!(
M::GeneralUnitaryMatrices{TypeParameter{2},ℝ},
M::GeneralUnitaryMatrices{TypeParameter{Tuple{2}},ℝ},
X,
p,
Xⁱ,
Expand Down
24 changes: 12 additions & 12 deletions test/groups/groups_general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ struct NotImplementedAction <: AbstractGroupAction{LeftForwardAction} end
a = [1.0, 2.0]
X = [1.0, 2.0]

@test_throws ErrorException apply(A, a, p)
@test_throws ErrorException apply!(A, p, a, p)
@test_throws ErrorException inverse_apply(A, a, p)
@test_throws ErrorException inverse_apply!(A, p, a, p)
@test_throws ErrorException apply_diff(A, a, p, X)
@test_throws ErrorException apply_diff!(A, X, p, a, X)
@test_throws ErrorException inverse_apply_diff(A, a, p, X)
@test_throws ErrorException inverse_apply_diff!(A, X, p, a, X)
@test_throws ErrorException compose(A, a, a)
@test_throws ErrorException compose!(A, a, a, a)
@test_throws ErrorException optimal_alignment(A, p, p)
@test_throws ErrorException optimal_alignment!(A, a, p, p)
@test_throws MethodError apply(A, a, p)
@test_throws MethodError apply!(A, p, a, p)
@test_throws MethodError inverse_apply(A, a, p)
@test_throws MethodError inverse_apply!(A, p, a, p)
@test_throws MethodError apply_diff(A, a, p, X)
@test_throws MethodError apply_diff!(A, X, p, a, X)
@test_throws MethodError inverse_apply_diff(A, a, p, X)
@test_throws MethodError inverse_apply_diff!(A, X, p, a, X)
@test_throws MethodError compose(A, a, a)
@test_throws MethodError compose!(A, a, a, a)
@test_throws MethodError optimal_alignment(A, p, p)
@test_throws MethodError optimal_alignment!(A, a, p, p)
end
end
Loading

0 comments on commit f8961e7

Please sign in to comment.