@@ -20,6 +20,7 @@ ArrayDomain(xs::NTuple{N,Base.OneTo}) where N =
20
20
ArrayDomain {N,NTuple{N,UnitRange{Int}}} (ntuple (i-> UnitRange (xs[i]), N))
21
21
ArrayDomain (xs:: NTuple{N,Int} ) where N =
22
22
ArrayDomain {N,NTuple{N,UnitRange{Int}}} (ntuple (i-> xs[i]: xs[i], N))
23
+ ArrayDomain (:: Tuple{} ) = ArrayDomain {0,Tuple{}} (())
23
24
ArrayDomain (xs... ) = ArrayDomain ((xs... ,))
24
25
ArrayDomain (xs:: Array ) = ArrayDomain ((xs... ,))
25
26
@@ -31,6 +32,7 @@ chunks(a::ArrayDomain{N}) where {N} = DomainBlocks(
31
32
32
33
(== )(a:: ArrayDomain , b:: ArrayDomain ) = indexes (a) == indexes (b)
33
34
Base. getindex (arr:: AbstractArray , d:: ArrayDomain ) = arr[indexes (d)... ]
35
+ Base. getindex (arr:: AbstractArray{T,0} where T, d:: ArrayDomain{0} ) = arr
34
36
35
37
function intersect (a:: ArrayDomain , b:: ArrayDomain )
36
38
if a === b
@@ -145,7 +147,6 @@ const WrappedDVector{T} = WrappedDArray{T,1}
145
147
const DMatrix{T} = DArray{T,2 }
146
148
const DVector{T} = DArray{T,1 }
147
149
148
-
149
150
# mainly for backwards-compatibility
150
151
DArray {T, N} (domain, subdomains, chunks, partitioning, concat= cat) where {T,N} =
151
152
DArray (T, domain, subdomains, chunks, partitioning, concat)
@@ -178,6 +179,10 @@ function Base.collect(d::DArray; tree=false)
178
179
return Array {eltype(d)} (undef, size (d)... )
179
180
end
180
181
182
+ if ndims (d) == 0
183
+ return fetch (a. chunks[1 ])
184
+ end
185
+
181
186
dimcatfuncs = [(x... ) -> d. concat (x... , dims= i) for i in 1 : ndims (d)]
182
187
if tree
183
188
collect (fetch (treereduce_nd (map (x -> ((args... ,) -> Dagger. @spawn x (args... )) , dimcatfuncs), a. chunks)))
214
219
Base. alignment (io:: IO , x:: ColorElement ) =
215
220
Base. alignment (io, something (x. value, " ..." ))
216
221
# end
222
+ Base. show (io:: IO , x:: ColorElement ) = show (io, MIME (" text/plain" ), x)
217
223
struct ColorArray{T,N} <: DenseArray{T,N}
218
224
A:: DArray{T,N}
219
225
color_map:: Vector{Symbol}
@@ -261,9 +267,21 @@ function Base.getindex(A::ColorArray{T,N}, idxs::Dims{S}) where {T,N,S}
261
267
end
262
268
end
263
269
function Base. show (io:: IO , :: MIME"text/plain" , A:: DArray{T,N} ) where {T,N}
264
- write (io, string (DArray{T,N}))
265
- write (io, string (size (A)))
266
- write (io, " with $(join (size (A. chunks), ' x' )) partitions of size $(join (A. partitioning. blocksize, ' x' )) :" )
270
+ if N == 1
271
+ write (io, " $(length (A)) -element " )
272
+ write (io, string (DVector{T}))
273
+ elseif N == 2
274
+ write (io, string (DMatrix{T}))
275
+ elseif N == 0
276
+ write (io, " 0-dimensional " )
277
+ write (io, " DArray{$T , $N }" )
278
+ else
279
+ write (io, " $(join (size (A), ' x' )) " )
280
+ write (io, " DArray{$T , $N }" )
281
+ end
282
+ nparts = N > 0 ? size (A. chunks) : 1
283
+ partsize = N > 0 ? A. partitioning. blocksize : 1
284
+ write (io, " with $(join (nparts, ' x' )) partitions of size $(join (partsize, ' x' )) :" )
267
285
pct_complete = 100 * (sum (c-> c isa Chunk ? true : isready (c), A. chunks) / length (A. chunks))
268
286
if pct_complete < 100
269
287
println (io)
@@ -472,7 +490,7 @@ struct AutoBlocks end
472
490
function auto_blocks (dims:: Dims{N} ) where N
473
491
# TODO : Allow other partitioning schemes
474
492
np = num_processors ()
475
- p = cld (dims[end ], np)
493
+ p = N > 0 ? cld (dims[end ], np) : 1
476
494
return Blocks (ntuple (i-> i == N ? p : dims[i], N))
477
495
end
478
496
auto_blocks (A:: AbstractArray{T,N} ) where {T,N} = auto_blocks (size (A))
0 commit comments