Skip to content

Commit

Permalink
fill! for array power manifold
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed May 19, 2024
1 parent 8c3a82b commit e8a622a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/PowerManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,19 @@ end
Fill a point `P` on the [`AbstractPowerManifold`](@ref) `M`, setting every entry to `p`.
!!! note
while usually the manifold is a first argument in all functions in `ManifoldsBase.jl`,
while usually the manifold is the first argument in all functions in `ManifoldsBase.jl`,
we follow the signature of `fill!`, where the power manifold serves are the size information.
"""
function fill!(P, p, M::PowerManifoldNestedReplacing)
for i in get_iterator(M)
P[i...] = p # can we do something that this is closer to fill/fill! and set the ref to p?
end
return P

Check warning on line 559 in src/PowerManifold.jl

View check run for this annotation

Codecov / codecov/patch

src/PowerManifold.jl#L555-L559

Added lines #L555 - L559 were not covered by tests
end
function fill!(P, p, M::AbstractPowerManifold)
rep_size = representation_size(M.manifold)
for i in get_iterator(M)
P[M, i] = p # can we do something that this is closer to fill/fill! and set the ref to p?
copyto!(M.manifold, _write(M, rep_size, P, i), p)
end
return P
end
Expand Down
33 changes: 32 additions & 1 deletion test/power.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using Test
using ManifoldsBase
using ManifoldsBase:
AbstractNumbers, ℝ, ℂ, NestedReplacingPowerRepresentation, VectorSpaceType
AbstractNumbers,
DefaultManifold,
ℝ,
ℂ,
NestedReplacingPowerRepresentation,
VectorSpaceType
using StaticArrays
using LinearAlgebra
using Random
Expand All @@ -24,6 +29,23 @@ end

struct TestArrayRepresentation <: AbstractPowerRepresentation end

const TestPowerManifoldMultidimensional =
AbstractPowerManifold{𝔽,<:AbstractManifold{𝔽},TestArrayRepresentation} where {𝔽}

function ManifoldsBase.representation_size(M::TestPowerManifoldMultidimensional)
return (representation_size(M.manifold)..., ManifoldsBase.get_parameter(M.size)...)
end

@inline function ManifoldsBase._write(
::TestPowerManifoldMultidimensional,
rep_size::Tuple,
x::AbstractArray,
i::Tuple,
)
return view(x, ManifoldsBase.rep_size_to_colons(rep_size)..., i...)
end


@testset "Power Manifold" begin

@testset "Power Manifold with a test representation" begin
Expand Down Expand Up @@ -400,5 +422,14 @@ struct TestArrayRepresentation <: AbstractPowerRepresentation end
fill!(P2, p, N)
@test P2[N, 1] == p
@test P2[N, 2] == p

NAR = PowerManifold(M, TestArrayRepresentation(), 2)
P1 = fill(p, NAR)
@test P1 isa Matrix{Float64}
@test P1 == [1.0 1.0; 2.0 2.0; 3.0 3.0]

P2 = similar(P1)
fill!(P2, p, NAR)
@test P2 == [1.0 1.0; 2.0 2.0; 3.0 3.0]
end
end

0 comments on commit e8a622a

Please sign in to comment.