@@ -174,17 +174,13 @@ end
174
174
BlockArray (arr:: AbstractArray{T, N} , block_sizes:: Vararg{AbstractVector{<:Integer}, N} ) where {T,N} =
175
175
BlockArray {T} (arr, block_sizes... )
176
176
177
- @generated function BlockArray {T} (arr:: AbstractArray{T, N} , baxes:: NTuple{N,AbstractUnitRange{Int}} ) where {T,N}
178
- return quote
179
- block_arr = _BlockArray (Array{typeof (arr),N}, baxes)
180
- @nloops $ N i i-> blockaxes (baxes[i],1 ) begin
181
- block_index = @ntuple $ N i
182
- indices = getindex .(baxes,block_index)
183
- block_arr[block_index... ] = arr[indices... ]
184
- end
185
-
186
- return block_arr
177
+ function BlockArray {T} (arr:: AbstractArray{T, N} , baxes:: NTuple{N,AbstractUnitRange{Int}} ) where {T,N}
178
+ block_arr = _BlockArray (Array{typeof (arr),N}, baxes)
179
+ for block_index in Iterators. product (blockaxes .(baxes,1 )... )
180
+ indices = getindex .(baxes,block_index)
181
+ block_arr[block_index... ] = arr[indices... ]
187
182
end
183
+ return block_arr
188
184
end
189
185
190
186
BlockArray {T} (arr:: AbstractArray{<:Any, N} , baxes:: NTuple{N,AbstractUnitRange{Int}} ) where {T,N} =
@@ -277,19 +273,17 @@ end
277
273
278
274
getsizes (block_sizes, block_index) = getindex .(block_sizes, block_index)
279
275
280
- @generated function checksizes (fullsizes:: Array{NTuple{N,Int}, N} , block_sizes:: NTuple{N,Vector{Int}} ) where N
281
- quote
282
- @nloops $ N i fullsizes begin
283
- block_index = @ntuple $ N i
284
- if fullsizes[block_index... ] != getsizes (block_sizes, block_index)
285
- error (" size(blocks[" , strip (repr (block_index), [' (' , ' )' ]),
286
- " ]) (= " , fullsizes[block_index... ],
287
- " ) is incompatible with expected size: " ,
288
- getsizes (block_sizes, block_index))
289
- end
276
+ function checksizes (fullsizes:: Array{NTuple{N,Int}, N} , block_sizes:: NTuple{N,Vector{Int}} ) where N
277
+ for I in CartesianIndices (fullsizes)
278
+ block_index = Tuple (I)
279
+ if fullsizes[block_index... ] != getsizes (block_sizes, block_index)
280
+ error (" size(blocks[" , strip (repr (block_index), [' (' , ' )' ]),
281
+ " ]) (= " , fullsizes[block_index... ],
282
+ " ) is incompatible with expected size: " ,
283
+ getsizes (block_sizes, block_index))
290
284
end
291
- return fullsizes
292
285
end
286
+ return fullsizes
293
287
end
294
288
295
289
"""
@@ -452,18 +446,13 @@ end
452
446
# Misc #
453
447
# #######
454
448
455
- @generated function Base. Array (block_array:: BlockArray{T, N, R} ) where {T,N,R}
456
- # TODO : This will fail for empty block array
457
- return quote
458
- arr = Array {eltype(T)} (undef, size (block_array))
459
- @nloops $ N i i-> blockaxes (block_array,i) begin
460
- block_index = @ntuple $ N i
461
- indices = getindex .(axes (block_array), block_index)
462
- arr[indices... ] = @view block_array[block_index... ]
463
- end
464
-
465
- return arr
449
+ function Base. Array (block_array:: BlockArray{T, N, R} ) where {T,N,R}
450
+ arr = Array {eltype(T)} (undef, size (block_array))
451
+ for block_index in Iterators. product (blockaxes (block_array)... )
452
+ indices = getindex .(axes (block_array), block_index)
453
+ arr[indices... ] = @view block_array[block_index... ]
466
454
end
455
+ return arr
467
456
end
468
457
469
458
function Base. fill! (block_array:: BlockArray , v)
0 commit comments