Skip to content

Commit b33a155

Browse files
committed
Add tests
1 parent e0863f4 commit b33a155

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/blockindices.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,21 @@ julia> a[BlockIndex((2,2), (2,3))]
141141
20
142142
```
143143
"""
144-
struct BlockIndex{N}
145-
I::NTuple{N, Int}
146-
α::NTuple{N, Int}
144+
struct BlockIndex{N,TI<:Tuple{Vararg{Integer,N}},Tα<:Tuple{Vararg{Integer,N}}}
145+
I::TI
146+
α::Tα
147147
end
148148

149149
@inline BlockIndex(a::NTuple{N,Block{1}}, b::Tuple) where N = BlockIndex(Int.(a), b)
150150

151-
@inline BlockIndex(a::Int, b::Int) = BlockIndex((a,), (b,))
152-
@inline BlockIndex(a::Tuple, b::Int) = BlockIndex(a, (b,))
153-
@inline BlockIndex(a::Int, b::Tuple) = BlockIndex((a,), b)
151+
@inline BlockIndex(a::Integer, b::Integer) = BlockIndex((a,), (b,))
152+
@inline BlockIndex(a::Tuple, b::Integer) = BlockIndex(a, (b,))
153+
@inline BlockIndex(a::Integer, b::Tuple) = BlockIndex((a,), b)
154154

155155
@inline BlockIndex(a::Block, b::Tuple) = BlockIndex(a.n, b)
156-
@inline BlockIndex(a::Block, b::Int) = BlockIndex(a, (b,))
156+
@inline BlockIndex(a::Block, b::Integer) = BlockIndex(a, (b,))
157157

158-
@inline function BlockIndex(I::NTuple{N, Int}, α::NTuple{M, Int}) where {M,N}
158+
@inline function BlockIndex(I::Tuple{Vararg{Integer,N}}, α::Tuple{Vararg{Integer,M}}) where {M,N}
159159
M <= N || throw(ArgumentError("number of indices must not exceed the number of blocks"))
160160
α2 = ntuple(k -> k <= M ? α[k] : 1, N)
161161
BlockIndex(I, α2)
@@ -164,7 +164,7 @@ end
164164
block(b::BlockIndex) = Block(b.I...)
165165
blockindex(b::BlockIndex{1}) = b.α[1]
166166

167-
BlockIndex(indcs::NTuple{N,BlockIndex{1}}) where N = BlockIndex(block.(indcs), blockindex.(indcs))
167+
BlockIndex(indcs::Tuple{Vararg{BlockIndex{1},N}}) where N = BlockIndex(block.(indcs), blockindex.(indcs))
168168

169169
##
170170
# checkindex
@@ -178,7 +178,7 @@ BlockIndex(indcs::NTuple{N,BlockIndex{1}}) where N = BlockIndex(block.(indcs), b
178178
checkbounds(Bool, B, blockindex(I)...)
179179
end
180180

181-
checkbounds(::Type{Bool}, A::AbstractArray{<:Any,N}, I::AbstractVector{BlockIndex{N}}) where N =
181+
checkbounds(::Type{Bool}, A::AbstractArray{<:Any,N}, I::AbstractVector{<:BlockIndex{N}}) where N =
182182
all(checkbounds.(Bool, Ref(A), I))
183183

184184
struct BlockIndexRange{N,R<:Tuple{Vararg{AbstractUnitRange{<:Integer}}}} <: AbstractArray{BlockIndex{N},N}
@@ -285,7 +285,7 @@ _indices(B) = B
285285
Block(bs::BlockSlice{<:BlockIndexRange}) = Block(bs.block)
286286

287287

288-
struct BlockRange{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{Block{N,Int},N}
288+
struct BlockRange{N,R<:NTuple{N,AbstractUnitRange{<:Integer}}} <: AbstractArray{Block{N,Int},N}
289289
indices::R
290290
BlockRange{N,R}(inds::R) where {N,R} = new{N,R}(inds)
291291
end
@@ -330,9 +330,9 @@ function BlockRange(inds::Tuple{BlockRange,Vararg{BlockRange}})
330330
BlockRange(combine_indices(inds))
331331
end
332332

333-
BlockRange(inds::Tuple{Vararg{AbstractUnitRange{Int}}}) =
333+
BlockRange(inds::Tuple{Vararg{AbstractUnitRange{<:Integer}}}) =
334334
BlockRange{length(inds),typeof(inds)}(inds)
335-
BlockRange(inds::Vararg{AbstractUnitRange{Int}}) = BlockRange(inds)
335+
BlockRange(inds::Vararg{AbstractUnitRange{<:Integer}}) = BlockRange(inds)
336336

337337
BlockRange() = BlockRange(())
338338
BlockRange(sizes::Tuple{Integer, Vararg{Integer}}) = BlockRange(map(oneto, sizes))
@@ -343,8 +343,8 @@ BlockRange(B::AbstractArray) = BlockRange(blockaxes(B))
343343
(:)(start::Block{1}, stop::Block{1}) = BlockRange((first(start.n):first(stop.n),))
344344
(:)(start::Block, stop::Block) = throw(ArgumentError("Use `BlockRange` to construct a cartesian range of blocks"))
345345
broadcasted(::DefaultArrayStyle{1}, ::Type{Block}, r::AbstractUnitRange) = BlockRange((r,))
346-
broadcasted(::DefaultArrayStyle{1}, ::Type{Int}, block_range::BlockRange{1}) = first(block_range.indices)
347-
broadcasted(::DefaultArrayStyle{0}, ::Type{Int}, block::Block{1}) = Int(block)
346+
broadcasted(::DefaultArrayStyle{1}, ::Type{<:Integer}, block_range::BlockRange{1}) = first(block_range.indices)
347+
broadcasted(::DefaultArrayStyle{0}, type::Type{<:Integer}, block::Block{1}) = type(block)
348348

349349

350350
# AbstractArray implementation

test/test_blockarrays.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ end
123123
@test all(isone, o)
124124
@test axes(o) == (br,)
125125
end
126+
127+
# non-Int block lengths
128+
blocklen = big(10)^30
129+
blks = [Fill(1.0, blocklen), Fill(2.0, blocklen)]
130+
ret = BlockArray{eltype(eltype(blks)),ndims(blks),typeof(blks)}(undef_blocks, [blocklen, blocklen])
131+
ret[Block(1)] = blks[1]
132+
ret[Block(2)] = blks[2]
133+
@test size(ret) == (2blocklen,)
134+
@test blocksize(ret) == (2,)
135+
@test blocklengths.(axes(ret)) == ([blocklen,blocklen],)
136+
@test ret[Block(1)] == Fill(1.0, blocklen)
137+
@test ret[Block(2)] == Fill(2.0, blocklen)
138+
@test ret[1] == 1.0
139+
@test ret[blocklen + 1] == 2.0
126140
end
127141

128142
@testset "BlockedArray constructors" begin

0 commit comments

Comments
 (0)