Skip to content

Commit fbc47a9

Browse files
author
Shashi Gowda
committed
Merge remote-tracking branch 'origin/master'
2 parents 3632514 + 3c051c4 commit fbc47a9

18 files changed

+189
-95
lines changed

Diff for: src/array/alloc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Base: cat
22
export partition
33

4-
type AllocateArray{T,N} <: ArrayOp{T,N}
4+
mutable struct AllocateArray{T,N} <: ArrayOp{T,N}
55
eltype::Type{T}
66
f::Function
77
domain::ArrayDomain{N}

Diff for: src/array/darray.jl

+18-25
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ using Compat
44

55
###### Array Domains ######
66

7-
if VERSION >= v"0.6.0-dev"
8-
# TODO: Fix this better!
9-
immutable ArrayDomain{N}
10-
indexes::NTuple{N, Any}
11-
end
12-
else
13-
immutable ArrayDomain{N}
14-
indexes::NTuple{N}
15-
end
7+
struct ArrayDomain{N}
8+
indexes::NTuple{N, Any}
169
end
1710

1811
include("../lib/domain-blocks.jl")
@@ -22,7 +15,7 @@ ArrayDomain(xs...) = ArrayDomain(xs)
2215
ArrayDomain(xs::Array) = ArrayDomain((xs...,))
2316

2417
indexes(a::ArrayDomain) = a.indexes
25-
chunks{N}(a::ArrayDomain{N}) = DomainBlocks(
18+
chunks(a::ArrayDomain{N}) where {N} = DomainBlocks(
2619
ntuple(i->first(indexes(a)[i]), Val{N}), map(x->[length(x)], indexes(a)))
2720

2821
(==)(a::ArrayDomain, b::ArrayDomain) = indexes(a) == indexes(b)
@@ -70,8 +63,8 @@ isempty(a::ArrayDomain) = length(a) == 0
7063
domain(x::AbstractArray) = ArrayDomain([1:l for l in size(x)])
7164

7265

73-
@compat abstract type ArrayOp{T, N} <: AbstractArray{T, N} end
74-
@compat Base.IndexStyle(::Type{<:ArrayOp}) = IndexCartesian()
66+
abstract type ArrayOp{T, N} <: AbstractArray{T, N} end
67+
Base.IndexStyle(::Type{<:ArrayOp}) = IndexCartesian()
7568

7669
compute(ctx, x::ArrayOp) =
7770
compute(ctx, cached_stage(ctx, x)::DArray)
@@ -81,14 +74,14 @@ collect(ctx::Context, x::ArrayOp) =
8174

8275
collect(x::ArrayOp) = collect(Context(), x)
8376

84-
@compat function Base.show(io::IO, ::MIME"text/plain", x::ArrayOp)
77+
function Base.show(io::IO, ::MIME"text/plain", x::ArrayOp)
8578
write(io, string(typeof(x)))
8679
write(io, string(size(x)))
8780
end
8881

8982
function Base.show(io::IO, x::ArrayOp)
9083
m = MIME"text/plain"()
91-
@compat show(io, m, x)
84+
show(io, m, x)
9285
end
9386

9487
"""
@@ -102,15 +95,15 @@ An N-dimensional distributed array of element type T.
10295
- `concat`: a function of type `F`. `concat(d, x, y)` takes two chunks `x` and `y`
10396
and concatenates them along dimension `d`. `cat` is used by default.
10497
"""
105-
type DArray{T,N,F} <: ArrayOp{T, N}
98+
mutable struct DArray{T,N,F} <: ArrayOp{T, N}
10699
domain::ArrayDomain{N}
107100
subdomains::AbstractArray{ArrayDomain{N}, N}
108101
chunks::AbstractArray{Union{Chunk,Thunk}, N}
109102
concat::F
110103
end
111104

112105
# mainly for backwards-compatibility
113-
(::Type{DArray{T, N}}){T,N}(domain, subdomains, chunks) = DArray(T, domain, subdomains, chunks)
106+
DArray{T, N}(domain, subdomains, chunks) where {T,N} = DArray(T, domain, subdomains, chunks)
114107

115108

116109
"""
@@ -122,9 +115,9 @@ Creates a distributed array of element type T.
122115
123116
rest of the arguments are the same as the DArray constructor.
124117
"""
125-
function DArray{N}(T, domain::ArrayDomain{N},
126-
subdomains::AbstractArray{ArrayDomain{N}, N},
127-
chunks::AbstractArray{<:Any, N}, concat=cat)
118+
function DArray(T, domain::ArrayDomain{N},
119+
subdomains::AbstractArray{ArrayDomain{N}, N},
120+
chunks::AbstractArray{<:Any, N}, concat=cat) where N
128121
DArray{T, N, typeof(concat)}(domain, subdomains, chunks, concat)
129122
end
130123

@@ -204,7 +197,7 @@ function group_indices(cumlength, idxs::Range)
204197
end
205198

206199
_cumsum(x::AbstractArray) = length(x) == 0 ? Int[] : cumsum(x)
207-
function lookup_parts{N}(ps::AbstractArray, subdmns::DomainBlocks{N}, d::ArrayDomain{N})
200+
function lookup_parts(ps::AbstractArray, subdmns::DomainBlocks{N}, d::ArrayDomain{N}) where N
208201
groups = map(group_indices, subdmns.cumlength, indexes(d))
209202
sz = map(length, groups)
210203
pieces = Array{Union{Chunk,Thunk}}(sz)
@@ -285,7 +278,7 @@ Base.@deprecate_binding ComputedArray DArray
285278

286279
export Distribute, distribute
287280

288-
immutable Distribute{T, N} <: ArrayOp{T, N}
281+
struct Distribute{T, N} <: ArrayOp{T, N}
289282
domainchunks
290283
data::AbstractArray{T,N}
291284
end
@@ -294,7 +287,7 @@ size(x::Distribute) = size(domain(x.data))
294287

295288
export BlockPartition, Blocks
296289

297-
immutable Blocks{N}
290+
struct Blocks{N}
298291
blocksize::NTuple{N, Int}
299292
end
300293
Blocks(xs::Int...) = Blocks(xs)
@@ -318,7 +311,7 @@ function distribute(x::AbstractArray, dist)
318311
compute(Distribute(dist, x))
319312
end
320313

321-
function distribute{T,N}(x::AbstractArray{T,N}, n::NTuple{N})
314+
function distribute(x::AbstractArray{T,N}, n::NTuple{N}) where {T,N}
322315
p = map((d, dn)->ceil(Int, d / dn), size(x), n)
323316
distribute(x, Blocks(p))
324317
end
@@ -331,10 +324,10 @@ function distribute(x::AbstractVector, n::Vector)
331324
distribute(x, DomainBlocks((1,), n))
332325
end
333326

334-
function Base.:(==){T,S,N}(x::ArrayOp{T,N}, y::AbstractArray{S,N})
327+
function Base.:(==)(x::ArrayOp{T,N}, y::AbstractArray{S,N}) where {T,S,N}
335328
collect(x) == y
336329
end
337330

338-
function Base.:(==){T,S,N}(x::AbstractArray{T,N}, y::ArrayOp{S,N})
331+
function Base.:(==)(x::AbstractArray{T,N}, y::ArrayOp{S,N}) where {T,S,N}
339332
return collect(x) == y
340333
end

Diff for: src/array/getindex.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export getindex_async
22

3-
immutable GetIndex{T,N} <: ArrayOp{T,N}
3+
struct GetIndex{T,N} <: ArrayOp{T,N}
44
input::ArrayOp
55
idx::Tuple
66
end
@@ -25,7 +25,7 @@ end
2525

2626
size(x::GetIndex) = Base.index_shape(x.input, x.idx...)
2727

28-
immutable GetIndexScalar <: Computation
28+
struct GetIndexScalar <: Computation
2929
input::ArrayOp
3030
idx::Tuple
3131
end

Diff for: src/array/map-reduce.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base: reduce, map, mapreduce, reducedim
33
export reducebykey, reduce_async
44

55
#### Map
6-
immutable Map{T,N} <: ArrayOp{T,N}
6+
struct Map{T,N} <: ArrayOp{T,N}
77
f::Function
88
inputs::Tuple
99
end
@@ -30,7 +30,7 @@ map(f, x::ArrayOp, xs::ArrayOp...) = Map(f, (x, xs...))
3030

3131
import Base: reduce, sum, prod, mean
3232

33-
immutable ReduceBlock <: Computation
33+
struct ReduceBlock <: Computation
3434
op::Function
3535
op_master::Function
3636
input::ArrayOp
@@ -83,7 +83,7 @@ reducebykey_seq(op, itr,dict=Dict()) = mapreducebykey_seq(Base.IdFun(), op, itr,
8383
reducebykey(op, input) = reduceblock(itr->reducebykey_seq(op, itr), merge_reducebykey(op), input)
8484

8585

86-
immutable Reducedim{T,N} <: ArrayOp{T,N}
86+
struct Reducedim{T,N} <: ArrayOp{T,N}
8787
op::Function
8888
input::ArrayOp
8989
dims::Tuple

Diff for: src/array/matrix.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import Base: ctranspose, transpose, A_mul_Bt, At_mul_B, Ac_mul_B, At_mul_Bt, Ac_mul_Bc, A_mul_Bc
33

4-
immutable Transpose{T,N} <: ArrayOp{T,N}
4+
struct Transpose{T,N} <: ArrayOp{T,N}
55
f::Function
66
input::ArrayOp
77
end
@@ -46,7 +46,7 @@ end
4646

4747
import Base: *, +
4848

49-
immutable MatMul{T, N} <: ArrayOp{T, N}
49+
struct MatMul{T, N} <: ArrayOp{T, N}
5050
a::ArrayOp
5151
b::ArrayOp
5252
end
@@ -152,7 +152,7 @@ end
152152
"""
153153
an operand which should be distributed as per convenience
154154
"""
155-
function stage_operands{T}(ctx, ::MatMul, a::ArrayOp, b::PromotePartition{T,1})
155+
function stage_operands(ctx, ::MatMul, a::ArrayOp, b::PromotePartition{T,1}) where T
156156
stg_a = cached_stage(ctx, a)
157157
dmn_a = domain(stg_a)
158158
dchunks_a = domainchunks(stg_a)
@@ -188,11 +188,11 @@ end
188188

189189
### Scale
190190

191-
immutable Scale{T,N} <: ArrayOp{T,N}
191+
struct Scale{T,N} <: ArrayOp{T,N}
192192
l::ArrayOp
193193
r::ArrayOp
194194
end
195-
Scale{Tl, Tr, N}(l::ArrayOp{Tl}, r::ArrayOp{Tr,N}) =
195+
Scale(l::ArrayOp{Tl}, r::ArrayOp{Tr,N}) where {Tl, Tr, N} =
196196
Scale{promote_type(Tl, Tr), N}(l,r)
197197

198198
size(s::Scale) = size(s.l)
@@ -230,7 +230,7 @@ function stage(ctx, scal::Scale)
230230
DArray(Any, domain(r), domainchunks(r), scal_parts)
231231
end
232232

233-
immutable Concat{T,N} <: ArrayOp{T,N}
233+
struct Concat{T,N} <: ArrayOp{T,N}
234234
axis::Int
235235
inputs::Tuple
236236
end

Diff for: src/array/operators.jl

+4-16
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ broadcast_ops = [ :.*, :.+, :.-, :.%, :./, :.^,
2727
This is a way of suggesting that stage should call
2828
stage_operand with the operation and other arguments
2929
"""
30-
immutable PromotePartition{T,N} <: ArrayOp{T,N}
30+
struct PromotePartition{T,N} <: ArrayOp{T,N}
3131
data::AbstractArray{T,N}
3232
end
3333

3434
size(p::PromotePartition) = size(domain(p.data))
3535

36-
immutable BCast{F, Ni, T, Nd} <: ArrayOp{T, Nd}
36+
struct BCast{F, Ni, T, Nd} <: ArrayOp{T, Nd}
3737
f::F
3838
input::NTuple{Ni, ArrayOp}
3939
end
4040

41-
function BCast{F}(f::F, input::Tuple)
41+
function BCast(f::F, input::Tuple) where F
4242
T = promote_type(map(eltype, input)...)
4343
Nd = reduce(max, map(ndims, input))
4444
BCast{F, length(input), T, Nd}(f, input)
@@ -86,18 +86,6 @@ for fn in blockwise_binary
8686
end
8787
end
8888

89-
if VERSION < v"0.6.0-dev"
90-
eval(:((.^)(x::Irrational{:e}, y::ArrayOp) = BCast(z -> x.^z, (y,))))
91-
for fn in broadcast_ops
92-
@eval begin
93-
$fn(x::ArrayOp, y::ArrayOp) = BCast($fn, (x, y))
94-
$fn(x::AbstractArray, y::ArrayOp) = BCast($fn, (PromotePartition(x), y))
95-
$fn(x::ArrayOp, y::AbstractArray) = BCast($fn, (x, PromotePartition(y)))
96-
$fn(x::Number, y::ArrayOp) = BCast(z -> $fn(x, z), (y,))
97-
$fn(x::ArrayOp, y::Number) = BCast(z -> $fn(z, y), (x,))
98-
end
99-
end
100-
end
10189

10290
Base.broadcast(fn::Function, x::ArrayOp, xs::ArrayOp...) = BCast(fn, (x, xs...))
10391
Base.broadcast(fn::Function, x::AbstractArray, y::ArrayOp) = BCast(fn, (PromotePartition(x), y))
@@ -143,7 +131,7 @@ end
143131

144132
export mappart, mapchunk
145133

146-
immutable MapChunk{F, Ni, T, Nd} <: ArrayOp{T, Nd}
134+
struct MapChunk{F, Ni, T, Nd} <: ArrayOp{T, Nd}
147135
f::F
148136
input::NTuple{Ni, ArrayOp{T,Nd}}
149137
end

Diff for: src/array/setindex.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
export setindex
33

4-
immutable SetIndex{T,N} <: ArrayOp{T,N}
4+
struct SetIndex{T,N} <: ArrayOp{T,N}
55
input::ArrayOp{T,N}
66
idx::Tuple
77
val

Diff for: src/array/sort.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Compat: view
33

44
import Base.Sort: Forward, Ordering, Algorithm, defalg, lt
55

6-
immutable Sort <: Computation
6+
struct Sort <: Computation
77
input::ArrayOp
88
alg::Algorithm
99
order::Ordering
@@ -244,7 +244,7 @@ function shuffle_merge(A, ranks, splitter_indices, ord)
244244
DArray(eltype(A), dmn, dmnchunks, map(x->x[1], thunks))
245245
end
246246

247-
function merge_sorted{T, S}(ord::Ordering, x::AbstractArray{T}, y::AbstractArray{S})
247+
function merge_sorted(ord::Ordering, x::AbstractArray{T}, y::AbstractArray{S}) where {T, S}
248248
n = length(x) + length(y)
249249
z = Array{promote_type(T,S)}(n)
250250
i = 1; j = 1; k = 1

Diff for: src/chunks.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function domain end
2020
"""
2121
Default domain -- has no information about the value
2222
"""
23-
immutable UnitDomain end
23+
struct UnitDomain end
2424

2525
"""
2626
If no `domain` method is defined on an object, then
@@ -33,7 +33,7 @@ domain(x::Any) = UnitDomain()
3333
"""
3434
A chunk with some data
3535
"""
36-
type Chunk{T, H}
36+
mutable struct Chunk{T, H}
3737
chunktype::Type{T}
3838
domain
3939
handle::H
@@ -45,7 +45,8 @@ chunktype(c::Chunk) = c.chunktype
4545
persist!(t::Chunk) = (t.persist=true; t)
4646
shouldpersist(p::Chunk) = t.persist
4747
affinity(c::Chunk) = affinity(c.handle)
48-
function unrelease{T}(c::Chunk{T,DRef})
48+
49+
function unrelease(c::Chunk{T,DRef}) where T
4950
# set spilltodisk = true if data is still around
5051
try
5152
destroyonevict(c.handle, false)
@@ -83,7 +84,7 @@ tochunk(x::Union{Chunk, Thunk}) = x
8384

8485
# Check to see if the node is set to persist
8586
# if it is foce can override it
86-
function free!{X}(s::Chunk{X, DRef}; force=true, cache=false)
87+
function free!(s::Chunk{X, DRef}; force=true, cache=false) where X
8788
if force || !s.persist
8889
if cache
8990
try

Diff for: src/compute.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ compute(ctx, c::Chunk) = c
77
collect(ctx::Context, c) = collect(ctx, compute(ctx, c))
88
collect(d::Union{Chunk,Thunk}) = collect(Context(), d)
99

10-
@compat abstract type Computation end
10+
abstract type Computation end
1111

1212
compute(ctx, c::Computation) = compute(ctx, stage(ctx, c))
1313
collect(c::Computation) = collect(Context(), c)

0 commit comments

Comments
 (0)