Repository: JuliaManifolds/ManifoldsBase.jl
Pull request #62 (2021-03-05 19:05:56)

Fix power indexing for the case of empty representation_size and inte…
This PR should replace #61 .

codecov[bot]: # [Codecov](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=h1) Report
> Merging [#62](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=desc) (e77c734) into [master](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/commit/fa09b2a96a09c9a371e7c6ab66445383f476e9d0?el=desc) (fa09b2a) will **decrease** coverage by `1.90%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/graphs/tree.svg?width=650&height=150&src=pr&token=bQsBUU9knE)](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #62      +/-   ##
==========================================
- Coverage   99.61%   97.71%   -1.91%     
==========================================
  Files          10       10              
  Lines        1303      962     -341     
==========================================
- Hits         1298      940     -358     
- Misses          5       22      +17     
```


| [Impacted Files](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/PowerManifold.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL1Bvd2VyTWFuaWZvbGQuamw=) | `98.11% <100.00%> (-0.61%)` | :arrow_down: |
| [src/EmbeddedManifold.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL0VtYmVkZGVkTWFuaWZvbGQuamw=) | `88.37% <0.00%> (-10.93%)` | :arrow_down: |
| [src/DecoratorManifold.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL0RlY29yYXRvck1hbmlmb2xkLmps) | `96.70% <0.00%> (-3.30%)` | :arrow_down: |
| [src/bases.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL2Jhc2VzLmps) | `98.15% <0.00%> (-1.85%)` | :arrow_down: |
| [src/ManifoldsBase.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL01hbmlmb2xkc0Jhc2Uuamw=) | `97.56% <0.00%> (-1.84%)` | :arrow_down: |
| [src/errors.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL2Vycm9ycy5qbA==) | `100.00% <0.00%> (ø)` | |
| [src/numbers.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL251bWJlcnMuamw=) | `100.00% <0.00%> (ø)` | |
| [src/DefaultManifold.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL0RlZmF1bHRNYW5pZm9sZC5qbA==) | `100.00% <0.00%> (ø)` | |
| [src/vector\_transport.jl](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree#diff-c3JjL3ZlY3Rvcl90cmFuc3BvcnQuamw=) | `100.00% <0.00%> (ø)` | |
| ... and [1 more](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=footer). Last update [fa09b2a...e77c734](https://codecov.io/gh/JuliaManifolds/ManifoldsBase.jl/pull/62?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

mateuszbaran: There is something weird going on... I need to investigate it a bit more.
kellertuer: Thanks for taking a look :) This looks simpler than my PR.

mateuszbaran: It looks like this change breaks `Manifolds.jl`. Do we tag 0.11.0 or consider it a bugfix and immediately release a fix for `Manifolds.jl`?
kellertuer: I would say it's a bugfix, since there was no way the `representation_size=()` cases worked with power manifolds.

Let's wait for my proper fix on `Project.toml` (I hope I found something) over on Manifolds, such that your tests and docs generation works in the sister-branch – then we should release both short after each other.

Patch:
diff --git a/Project.toml b/Project.toml
index 2f63a1df..d053e0f4 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,7 +1,7 @@
 name = "ManifoldsBase"
 uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
 authors = ["Seth Axen <seth.axen@gmail.com>", "Mateusz Baran <mateuszbaran89@gmail.com>", "Ronny Bergmann <manopt@ronnybergmann.net>", "Antoine Levitt <antoine.levitt@gmail.com>"]
-version = "0.10.2"
+version = "0.10.3"
 
 [deps]
 LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
diff --git a/src/PowerManifold.jl b/src/PowerManifold.jl
index 8977e016..316e6f99 100644
--- a/src/PowerManifold.jl
+++ b/src/PowerManifold.jl
@@ -173,10 +173,14 @@ function Base.:^(
 end
 
 function allocate_result(M::PowerManifoldNested, f, x...)
-    return [
-        allocate_result(M.manifold, f, map(y -> _access_nested(y, i), x)...) for
-        i in get_iterator(M)
-    ]
+    if representation_size(M.manifold) === ()
+        return allocate(x[1])
+    else
+        return [
+            allocate_result(M.manifold, f, map(y -> _access_nested(y, i), x)...) for
+            i in get_iterator(M)
+        ]
+    end
 end
 
 function allocate_result(
@@ -488,13 +492,6 @@ Base.@propagate_inbounds function Base.getindex(
 )
     return get_component(M, p, I...)
 end
-Base.@propagate_inbounds function Base.getindex(
-    p::AbstractArray,
-    M::AbstractPowerManifold,
-    I::Integer...,
-)
-    return collect(get_component(M, p, I...))
-end
 
 @doc raw"""
     injectivity_radius(M::AbstractPowerManifold[, p])
@@ -757,7 +754,7 @@ Base.@propagate_inbounds @inline function _read(
     x::AbstractArray,
     i::Tuple,
 )
-    return view(x[i...], rep_size_to_colons(rep_size)...)
+    return x[i...]
 end
 
 @generated function rep_size_to_colons(rep_size::Tuple)
@@ -974,6 +971,14 @@ end
 @inline function _write(M::PowerManifoldNested, rep_size::Tuple, x::AbstractArray, i::Tuple)
     return view(x[i...], rep_size_to_colons(rep_size)...)
 end
+@inline function _write(
+    M::PowerManifoldNested,
+    rep_size::Tuple{},
+    x::AbstractArray,
+    i::Tuple,
+)
+    return view(x, i...)
+end
 
 function zero_tangent_vector!(M::AbstractPowerManifold, X, p)
     rep_size = representation_size(M.manifold)


Test patch:
diff --git a/test/power.jl b/test/power.jl
index 5f8ce4f1..87560833 100644
--- a/test/power.jl
+++ b/test/power.jl
@@ -114,4 +114,12 @@ struct DummyPowerRepresentation <: AbstractPowerRepresentation end
         """
     end
 
+    @testset "Zero index manifold" begin
+        M = ManifoldsBase.DefaultManifold()
+        N = PowerManifold(M, NestedPowerRepresentation(), 3)
+        p = [1.0, 2.0, 3.0]
+
+        @test p[N, 1] == 1.0
+        @test zero_tangent_vector(N, p) == zero(p)
+    end
 end