diff --git a/src/array/alloc.jl b/src/array/alloc.jl index 7f531de6..5007cffd 100644 --- a/src/array/alloc.jl +++ b/src/array/alloc.jl @@ -9,13 +9,6 @@ type AllocateArray{T,N} <: ArrayOp{T,N} end size(a::AllocateArray) = size(a.domain) -export BlockPartition, Blocks - -immutable Blocks{N} - blocksize::NTuple{N, Int} -end -Blocks(xs::Int...) = Blocks(xs) - function _cumlength(len, step) nice_pieces = div(len, step) extra = rem(len, step) @@ -28,8 +21,6 @@ function partition(p::Blocks, dom::ArrayDomain) map(_cumlength, map(length, indexes(dom)), p.blocksize)) end -Base.@deprecate BlockPartition Blocks - function stage(ctx, a::AllocateArray) alloc(idx, sz) = a.f(idx, a.eltype, sz) thunks = [delayed(alloc)(i, size(x)) for (i, x) in enumerate(a.domainchunks)] diff --git a/src/array/darray.jl b/src/array/darray.jl index cb5133d9..9fa3d2f1 100644 --- a/src/array/darray.jl +++ b/src/array/darray.jl @@ -292,3 +292,55 @@ end Base.@deprecate_binding Cat DArray Base.@deprecate_binding ComputedArray DArray + +export Distribute, distribute + +immutable Distribute{N, T} <: ArrayOp{N, T} + domainchunks + data::Union{Chunk, Thunk} +end + +Distribute(dmn, data) = + Distribute(dmn, persist!(tochunk(data))) + +Distribute(d, p::Union{Chunk, Thunk}) = + Distribute{eltype(chunktype(p)), ndims(d)}(d, p) + +size(x::Distribute) = size(domain(x.data)) + +export BlockPartition, Blocks + +immutable Blocks{N} + blocksize::NTuple{N, Int} +end +Blocks(xs::Int...) = Blocks(xs) + +Base.@deprecate BlockPartition Blocks + + +Distribute(p::Blocks, data) = + Distribute(partition(p, domain(data)), data) + +function stage(ctx, d::Distribute) + DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}( + domain(d.data), + d.domainchunks, + map(c -> delayed(getindex)(d.data, c), d.domainchunks)) +end + +function distribute(x::AbstractArray, dist) + compute(Distribute(dist, x)) +end + +function distribute{T,N}(x::AbstractArray{T,N}, n::NTuple{N}) + p = map((d, dn)->ceil(Int, d / dn), size(x), n) + distribute(x, Blocks(p)) +end + +function distribute(x::AbstractVector, n::Int) + distribute(x, (n,)) +end + +function distribute(x::AbstractVector, n::Vector) + distribute(x, DomainBlocks((1,), n)) +end diff --git a/src/array/matrix.jl b/src/array/matrix.jl index 1823b677..57351c2e 100644 --- a/src/array/matrix.jl +++ b/src/array/matrix.jl @@ -44,33 +44,6 @@ function stage(ctx, node::Transpose) DArray{eltype(inp),ndims(inp)}(domain(inp)', domainchunks(inp)', thunks) end -export Distribute - -immutable Distribute{N, T} <: ArrayOp{N, T} - domainchunks - data::Union{Chunk, Thunk} -end - -Distribute(dmn, data) = - Distribute(dmn, persist!(tochunk(data))) - -Distribute(d, p::Union{Chunk, Thunk}) = - Distribute{eltype(chunktype(p)), ndims(d)}(d, p) - -size(x::Distribute) = size(domain(x.data)) - - -Distribute(p::Blocks, data) = - Distribute(partition(p, domain(data)), data) - -function stage(ctx, d::Distribute) - DArray{eltype(chunktype(d.data)), ndims(domain(d.data))}( - domain(d.data), - d.domainchunks, - map(c -> delayed(getindex)(d.data, c), d.domainchunks)) -end - - import Base: *, + immutable MatMul{T, N} <: ArrayOp{T, N}