Skip to content

Commit 651ca96

Browse files
authored
Fix #108 (#109)
1 parent 2555908 commit 651ca96

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.12.2"
3+
version = "0.12.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockaxis.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
@inline getindex(b::AbstractVector, K::BlockIndex{1}) = b[Block(K.I[1])][K.α[1]]
55
@inline getindex(b::AbstractArray{T,N}, K::BlockIndex{N}) where {T,N} =
66
b[block(K)][K.α...]
7-
@inline getindex(b::AbstractArray{T,N}, K::Vararg{BlockIndex{1},N}) where {T,N} =
8-
b[BlockIndex(K)]
7+
@inline getindex(b::AbstractArray, K::BlockIndex{1}, J::BlockIndex{1}...) =
8+
b[BlockIndex(tuple(K, J...))]
99

1010
@inline getindex(b::AbstractArray{T,N}, K::BlockIndexRange{N}) where {T,N} =
1111
b[block(K)][K.indices...]

src/blockindices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ end
128128
end
129129
end
130130

131-
block(b::BlockIndex{1}) = Block(b.I[1])
131+
block(b::BlockIndex) = Block(b.I...)
132132
blockindex(b::BlockIndex{1}) = b.α[1]
133133

134134
BlockIndex(indcs::NTuple{N,BlockIndex{1}}) where N = BlockIndex(block.(indcs), blockindex.(indcs))

test/test_blockindices.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ end
106106
@test_throws BlockBoundsError b[Block(0)]
107107
@test_throws BlockBoundsError b[Block(4)]
108108

109-
o = OffsetArray([2,2,3],-1:1)
109+
o = OffsetArray([2,2,3],-1:1)
110110
b = BlockArrays._BlockedUnitRange(-3, cumsum(o) .- 4)
111111
@test axes(b,1) == blockedrange([2,2,3])
112112
@test b[Block(-1)] == -3:-2
113113
@test b[Block(0)] == -1:0
114114
@test b[Block(1)] == 1:3
115115
@test_throws BlockBoundsError b[Block(-2)]
116-
@test_throws BlockBoundsError b[Block(2)]
116+
@test_throws BlockBoundsError b[Block(2)]
117117

118118
b = blockedrange(Fill(3,1_000_000))
119119
@test b isa BlockedUnitRange{StepRange{Int,Int}}
@@ -138,7 +138,7 @@ end
138138
@test blockisequal(convert(BlockedUnitRange, Base.IdentityUnitRange(-2:2)), BlockArrays._BlockedUnitRange(-2,[2]))
139139
@test convert(BlockedUnitRange{Vector{Int}}, c) === c
140140
@test blockisequal(convert(BlockedUnitRange{Vector{Int}}, b),b)
141-
@test blockisequal(convert(BlockedUnitRange{Vector{Int}}, Base.OneTo(5)), blockedrange([5]))
141+
@test blockisequal(convert(BlockedUnitRange{Vector{Int}}, Base.OneTo(5)), blockedrange([5]))
142142
end
143143

144144
@testset "findblock" begin
@@ -173,37 +173,37 @@ end
173173
@test_throws BoundsError findblockindex(b,-2)
174174
@test_throws BoundsError findblockindex(b,5)
175175

176-
o = OffsetArray([2,2,3],-1:1)
177-
b = BlockArrays._BlockedUnitRange(-3, cumsum(o) .- 4)
178-
@test @inferred(findblock(b,-3)) == Block(-1)
176+
o = OffsetArray([2,2,3],-1:1)
177+
b = BlockArrays._BlockedUnitRange(-3, cumsum(o) .- 4)
178+
@test @inferred(findblock(b,-3)) == Block(-1)
179179
@test @inferred(findblockindex(b,-3)) == Block(-1)[1]
180180
@test findblock.(Ref(b),-3:3) == Block.([-1,-1,0,0,1,1,1])
181181
@test findblockindex.(Ref(b),-3:3) == BlockIndex.([-1,-1,0,0,1,1,1], [1,2,1,2,1,2,3])
182182
@test_throws BoundsError findblock(b,-4)
183-
@test_throws BoundsError findblock(b,5)
183+
@test_throws BoundsError findblock(b,5)
184184
@test_throws BoundsError findblockindex(b,-4)
185-
@test_throws BoundsError findblockindex(b,5)
186-
185+
@test_throws BoundsError findblockindex(b,5)
186+
187187
b = blockedrange(Fill(3,1_000_000))
188188
@test @inferred(findblock(b, 1)) == Block(1)
189189
@test @inferred(findblockindex(b, 1)) == Block(1)[1]
190190
@test findblock.(Ref(b),299_997:300_001) == Block.([99_999,100_000,100_000,100_000,100_001])
191191
@test findblockindex.(Ref(b),299_997:300_001) == BlockIndex.([99_999,100_000,100_000,100_000,100_001],[3,1,2,3,1])
192192
@test_throws BoundsError findblock(b,0)
193-
@test_throws BoundsError findblock(b,3_000_001)
193+
@test_throws BoundsError findblock(b,3_000_001)
194194
@test_throws BoundsError findblockindex(b,0)
195-
@test_throws BoundsError findblockindex(b,3_000_001)
195+
@test_throws BoundsError findblockindex(b,3_000_001)
196196
end
197197

198198
@testset "BlockIndex indexing" begin
199-
b = blockedrange([1,2,3])
199+
b = blockedrange([1,2,3])
200200
@test b[Block(3)[2]] == b[Block(3)][2] == 5
201201
@test b[Block(3)[2:3]] == b[Block(3)][2:3] == 5:6
202202
end
203203

204204
@testset "BlockRange indexing" begin
205-
b = blockedrange([1,2,3])
206-
@test b[Block.(1:2)] == blockedrange([1,2])
205+
b = blockedrange([1,2,3])
206+
@test b[Block.(1:2)] == blockedrange([1,2])
207207
@test b[Block.(1:3)] == b
208208
@test_throws BlockBoundsError b[Block.(0:2)]
209209
@test_throws BlockBoundsError b[Block.(1:4)]
@@ -232,7 +232,11 @@ end
232232
@test_throws BoundsError findblock(b,0)
233233
@test_throws BoundsError findblock(b,6)
234234
@test stringmime("text/plain",blockedrange([1,2,2])) == "3-blocked 5-element BlockedUnitRange{Array{Int64,1}}:\n 1\n\n 2\n 3\n\n 4\n 5"
235-
end
235+
end
236+
237+
@testset "BlockIndex type piracy (#108)" begin
238+
@test zeros()[] == 0.0
239+
end
236240
end
237241

238242
@testset "BlockSlice" begin
@@ -257,7 +261,7 @@ end
257261
# @test A[Block(2)[2]] == 3
258262
# @test A[Block(2)[1:2]] == [2,3]
259263
# @test A[getindex.(Block.(1:2), 1)] == [1,2]
260-
264+
261265
# @test_throws BlockBoundsError A[Block(3)]
262266
# @test_throws BlockBoundsError A[Block(3)[1]]
263267
# @test_throws BoundsError A[Block(3)[1:1]] # this is likely an error

0 commit comments

Comments
 (0)