Skip to content

Commit dd3ac2c

Browse files
authored
Merge pull request #111 from fverdugo/add_collect
Implemented Base.collect(::PVector)
2 parents ea717f7 + 0e2b855 commit dd3ac2c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/p_vector.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,22 @@ function Base.minimum(f::Function,x::PVector)
641641
reduce(min,partials,init=typemax(eltype(x)))
642642
end
643643

644+
function Base.collect(v::PVector)
645+
own_values_v = own_values(v)
646+
own_to_global_v = map(own_to_global,partition(axes(v,1)))
647+
vals = gather(own_values_v,destination=:all)
648+
ids = gather(own_to_global_v,destination=:all)
649+
n = length(v)
650+
T = eltype(v)
651+
map(vals,ids) do myvals,myids
652+
u = Vector{T}(undef,n)
653+
for (a,b) in zip(myvals,myids)
654+
u[b] = a
655+
end
656+
u
657+
end |> getany
658+
end
659+
644660
function Base.:*(a::Number,b::PVector)
645661
values = map(partition(b)) do values
646662
a*values

test/p_vector_tests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function p_vector_tests(distribute)
116116
@test values == [0.0, 0.0, 0.0, 10.0, 30.0]
117117
end
118118
end
119+
@test collect(v) == [20.0, 20.0, 20.0, 20.0, 30.0, 10.0, 30.0, 20.0, 10.0, 30.0]
119120

120121
n = 10
121122

0 commit comments

Comments
 (0)