You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generalize BlockArray/BlockedArray to non-integer block lengths (#405)
* Generalize element type of axes
* Try fixing tests
* Fix ambiguity error in reshape
* Fix BlockMatrix and BlockedMatrix constructors
* Fix more constructors
* Fix broadcasting
* Fix broadcasting
* Fix broadcasting
* Add tests
* Add BlockedArray tests
* Fix test
* Fix some coverage issues
* More test coverage
* More test coverage
* More test coverage, redesign BlockIndexRange
* Generalize blockaxis.jl
* Revert definition of DefaultBlockAxis to fix downstream test failures
* Fix dispatch issue
BlockArray{T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractBlockArray{T, N}
54
+
BlockArray{T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} <: AbstractBlockArray{T, N}
55
55
56
56
A `BlockArray` is an array where each block is stored contiguously. This means that insertions and retrieval of blocks
57
57
can be very fast and non allocating since no copying of data is needed.
58
58
59
59
In the type definition, `R` defines the array type that holds the blocks, for example `Matrix{Matrix{Float64}}`.
60
60
"""
61
-
struct BlockArray{T, N, R <:AbstractArray{<:AbstractArray{T,N},N}, BS<:NTuple{N,AbstractUnitRange{Int}}} <:AbstractBlockArray{T, N}
61
+
struct BlockArray{T, N, R <:AbstractArray{<:AbstractArray{T,N},N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} <:AbstractBlockArray{T, N}
62
62
blocks::R
63
63
axes::BS
64
64
65
-
global@inlinefunction_BlockArray(blocks::R, block_axes::BS) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:NTuple{N,AbstractUnitRange{Int}}}
65
+
global@inlinefunction_BlockArray(blocks::R, block_axes::BS) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}}
_BlockArray(blocks::R, block_axes::BS) where {N, R<:AbstractArray{<:AbstractArray{V,N} where V,N}, BS<:NTuple{N,AbstractUnitRange{Int}}} =
77
+
_BlockArray(blocks::R, block_axes::BS) where {N, R<:AbstractArray{<:AbstractArray{V,N} where V,N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} =
@inline_BlockArray(::Type{R}, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}} =
91
91
_BlockArray(R, map(blockedrange,block_sizes))
92
92
93
-
function_BlockArray(::Type{R}, baxes::NTuple{N,AbstractUnitRange{Int}}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}}
93
+
function_BlockArray(::Type{R}, baxes::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}}
94
94
n_blocks =map(blocklength,baxes)
95
95
blocks =R(undef, n_blocks)
96
96
_BlockArray(blocks, baxes)
@@ -186,7 +186,7 @@ See also [`undef_blocks`](@ref), [`UndefBlocksInitializer`](@ref)
186
186
@inlineBlockArray{T,N,R}(::UndefBlocksInitializer, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}} =
187
187
undef_blocks_BlockArray(R, block_sizes...)
188
188
189
-
functioninitialized_blocks_BlockArray(::Type{R}, baxes::NTuple{N,AbstractUnitRange{Int}}) where R<:AbstractArray{V,N}where {T,N,V<:AbstractArray{T,N}}
189
+
functioninitialized_blocks_BlockArray(::Type{R}, baxes::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}) where R<:AbstractArray{V,N}where {T,N,V<:AbstractArray{T,N}}
190
190
blocks =map(Iterators.product(map(x ->blockaxes(x,1), baxes)...)) do block_index
191
191
indices =map((x,y) -> x[y], baxes, block_index)
192
192
similar(V, map(length, indices))
@@ -198,16 +198,16 @@ end
198
198
initialized_blocks_BlockArray(::Type{R}, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}} =
@inlineBlockArray{T, N, R}(::UndefInitializer, baxes::NTuple{N,AbstractUnitRange{Int}}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}} =
207
+
@inlineBlockArray{T, N, R}(::UndefInitializer, baxes::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}} =
208
208
initialized_blocks_BlockArray(R, baxes)
209
209
210
-
@inlineBlockArray{T,N,R,BS}(::UndefInitializer, baxes::BS) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:NTuple{N,AbstractUnitRange{Int}}} =
210
+
@inlineBlockArray{T,N,R,BS}(::UndefInitializer, baxes::BS) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} =
211
211
initialized_blocks_BlockArray(R, baxes)
212
212
213
213
"""
@@ -242,7 +242,7 @@ julia> B
242
242
initialized_blocks_BlockArray(R, block_sizes...)
243
243
244
244
245
-
@inlineBlockArray{T,N,R,BS}(::UndefInitializer, sizes::NTuple{N,Int}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:NTuple{N,AbstractUnitRange{Int}}} =
245
+
@inlineBlockArray{T,N,R,BS}(::UndefInitializer, sizes::Tuple{Vararg{Integer, N}}) where {T, N, R<:AbstractArray{<:AbstractArray{T,N},N}, BS<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} =
functionchecksizes(fullsizes::Array{NTuple{N,Int}, N}, block_sizes::NTuple{N,Vector{Int}}) where N
358
+
functionchecksizes(fullsizes::Array{<:Tuple{Vararg{Integer,N}}, N}, block_sizes::Tuple{Vararg{Vector{<:Integer},N}}) where N
359
359
for I inCartesianIndices(fullsizes)
360
360
block_index =Tuple(I)
361
361
if fullsizes[block_index...] !=getsizes(block_sizes, block_index)
@@ -431,18 +431,18 @@ end
431
431
###########################
432
432
433
433
434
-
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
434
+
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
435
435
BlockArray{T}(undef, map(to_axes,axes))
436
-
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
436
+
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
437
437
BlockArray{T}(undef, map(to_axes,axes))
438
-
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{Union{AbstractUnitRange{Int},Integer},AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
438
+
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{Union{AbstractUnitRange{<:Integer},Integer},AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
439
439
BlockArray{T}(undef, map(to_axes,axes))
440
440
441
-
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
441
+
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
442
442
BlockArray{T}(undef, map(to_axes,axes))
443
-
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
443
+
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
444
444
BlockArray{T}(undef, map(to_axes,axes))
445
-
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{Union{AbstractUnitRange{Int},Integer},AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{Int},Integer}}}) where T =
445
+
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{Union{AbstractUnitRange{<:Integer},Integer},AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T =
446
446
BlockArray{T}(undef, map(to_axes,axes))
447
447
448
448
@inline Base.similar(B::BlockArray, ::Type{T}) where {T} =mortar(similar.(blocks(B), T))
0 commit comments