Skip to content

Commit

Permalink
introduces getindex for decorators (#72)
Browse files Browse the repository at this point in the history
* introduces getindex for decorators
  • Loading branch information
kellertuer authored May 22, 2021
1 parent 6d18ffd commit a805e8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ManifoldsBase"
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"]
version = "0.11.1"
version = "0.11.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
11 changes: 11 additions & 0 deletions src/DecoratorManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,14 @@ decorated_manifold(M::AbstractManifold) = M.manifold

@decorator_transparent_signature zero_vector(M::AbstractDecoratorManifold, p)
@decorator_transparent_signature zero_vector!(M::AbstractDecoratorManifold, X, p)

#
# Manually patch getindex not using the whole machinery
#
Base.@propagate_inbounds function Base.getindex(
p::AbstractArray,
M::AbstractDecoratorManifold,
I::Union{Integer,Colon,AbstractVector}...,
)
return getindex(p, decorated_manifold(M), I...)
end
11 changes: 11 additions & 0 deletions test/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ using ManifoldsBase
using ManifoldsBase: AbstractNumbers, ℝ, ℂ

struct DummyPowerRepresentation <: AbstractPowerRepresentation end
struct DummyDecorator{TM<:AbstractManifold{ManifoldsBase.ℝ}} <:
AbstractDecoratorManifold{ManifoldsBase.ℝ}
manifold::TM
end

@testset "Power AbstractManifold" begin
M = ManifoldsBase.DefaultManifold(3)
Expand Down Expand Up @@ -129,4 +133,11 @@ struct DummyPowerRepresentation <: AbstractPowerRepresentation end
@test p[N, 1] == 1.0
@test zero_vector(N, p) == zero(p)
end
@testset "Decorator passthrough for getindex" begin
M = ManifoldsBase.DefaultManifold()
N = PowerManifold(M, NestedPowerRepresentation(), 3)
p = [1.0, 2.0, 3.0]
DN = DummyDecorator(N)
@test p[DN, 1] == p[N, 1]
end
end

2 comments on commit a805e8e

@kellertuer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/37277

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.2 -m "<description of version>" a805e8ea00d9fba9aad68c4c491d0e60d1f9ca73
git push origin v0.11.2

Please sign in to comment.