Skip to content

Commit 8f7f2b1

Browse files
author
Shashi Gowda
committed
distribute
1 parent c3e4c38 commit 8f7f2b1

File tree

3 files changed

+52
-36
lines changed

3 files changed

+52
-36
lines changed

Diff for: src/array/alloc.jl

-9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ type AllocateArray{T,N} <: ArrayOp{T,N}
99
end
1010
size(a::AllocateArray) = size(a.domain)
1111

12-
export BlockPartition, Blocks
13-
14-
immutable Blocks{N}
15-
blocksize::NTuple{N, Int}
16-
end
17-
Blocks(xs::Int...) = Blocks(xs)
18-
1912
function _cumlength(len, step)
2013
nice_pieces = div(len, step)
2114
extra = rem(len, step)
@@ -28,8 +21,6 @@ function partition(p::Blocks, dom::ArrayDomain)
2821
map(_cumlength, map(length, indexes(dom)), p.blocksize))
2922
end
3023

31-
Base.@deprecate BlockPartition Blocks
32-
3324
function stage(ctx, a::AllocateArray)
3425
alloc(idx, sz) = a.f(idx, a.eltype, sz)
3526
thunks = [delayed(alloc)(i, size(x)) for (i, x) in enumerate(a.domainchunks)]

Diff for: src/array/darray.jl

+52
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,55 @@ end
292292

293293
Base.@deprecate_binding Cat DArray
294294
Base.@deprecate_binding ComputedArray DArray
295+
296+
export Distribute, distribute
297+
298+
immutable Distribute{N, T} <: ArrayOp{N, T}
299+
domainchunks
300+
data::Union{Chunk, Thunk}
301+
end
302+
303+
Distribute(dmn, data) =
304+
Distribute(dmn, persist!(tochunk(data)))
305+
306+
Distribute(d, p::Union{Chunk, Thunk}) =
307+
Distribute{eltype(chunktype(p)), ndims(d)}(d, p)
308+
309+
size(x::Distribute) = size(domain(x.data))
310+
311+
export BlockPartition, Blocks
312+
313+
immutable Blocks{N}
314+
blocksize::NTuple{N, Int}
315+
end
316+
Blocks(xs::Int...) = Blocks(xs)
317+
318+
Base.@deprecate BlockPartition Blocks
319+
320+
321+
Distribute(p::Blocks, data) =
322+
Distribute(partition(p, domain(data)), data)
323+
324+
function stage(ctx, d::Distribute)
325+
DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}(
326+
domain(d.data),
327+
d.domainchunks,
328+
map(c -> delayed(getindex)(d.data, c), d.domainchunks))
329+
end
330+
331+
function distribute(x::AbstractArray, dist)
332+
compute(Distribute(dist, x))
333+
end
334+
335+
function distribute{T,N}(x::AbstractArray{T,N}, n::NTuple{N})
336+
p = map((d, dn)->ceil(Int, d / dn), size(x), n)
337+
distribute(x, Blocks(p))
338+
end
339+
340+
function distribute(x::AbstractVector, n::Int)
341+
distribute(x, (n,))
342+
end
343+
344+
function distribute(x::AbstractVector, n::Vector)
345+
distribute(x, DomainBlocks((1,), n))
346+
end

Diff for: src/array/matrix.jl

-27
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,6 @@ function stage(ctx, node::Transpose)
4444
DArray{eltype(inp),ndims(inp)}(domain(inp)', domainchunks(inp)', thunks)
4545
end
4646

47-
export Distribute
48-
49-
immutable Distribute{N, T} <: ArrayOp{N, T}
50-
domainchunks
51-
data::Union{Chunk, Thunk}
52-
end
53-
54-
Distribute(dmn, data) =
55-
Distribute(dmn, persist!(tochunk(data)))
56-
57-
Distribute(d, p::Union{Chunk, Thunk}) =
58-
Distribute{eltype(chunktype(p)), ndims(d)}(d, p)
59-
60-
size(x::Distribute) = size(domain(x.data))
61-
62-
63-
Distribute(p::Blocks, data) =
64-
Distribute(partition(p, domain(data)), data)
65-
66-
function stage(ctx, d::Distribute)
67-
DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}(
68-
domain(d.data),
69-
d.domainchunks,
70-
map(c -> delayed(getindex)(d.data, c), d.domainchunks))
71-
end
72-
73-
7447
import Base: *, +
7548

7649
immutable MatMul{T, N} <: ArrayOp{T, N}

0 commit comments

Comments
 (0)