Skip to content

Commit d9c8b02

Browse files
committed
More tests
1 parent 18687b2 commit d9c8b02

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/BlockArraysExtensions/blockedunitrange.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,6 @@ _getindex(a::Block{N}, b::Vararg{Integer,N}) where {N} = a[b...]
299299
# Fix ambiguity.
300300
_getindex(a::Block{0}) = a[]
301301

302-
## function blockindextype(TB::Type{<:Integer}, TI::Vararg{Type{<:Integer},N}) where {N}
303-
## return BlockIndex{N,NTuple{N,TB},Tuple{TI...}}
304-
## end
305-
## function blockindextype(TB::Type{<:Integer}, TI::Vararg{Type,N}) where {N}
306-
## return GenericBlockIndex{N,NTuple{N,TB},Tuple{TI...}}
307-
## end
308-
309302
struct BlockIndexVector{N,BT,I<:NTuple{N,AbstractVector},TB<:Integer} <: AbstractArray{BT,N}
310303
block::Block{N,TB}
311304
indices::I
@@ -337,7 +330,7 @@ BlockArrays.Block(b::BlockIndexVector) = b.block
337330
Base.copy(a::BlockIndexVector) = BlockIndexVector(a.block, copy.(a.indices))
338331

339332
function Base.getindex(b::AbstractBlockedUnitRange, Kkr::BlockIndexVector{1})
340-
b[block(Kkr)][Kkr.indices...]
333+
return b[block(Kkr)][Kkr.indices...]
341334
end
342335

343336
using ArrayLayouts: LayoutArray

test/test_genericblockindex.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BlockArrays: Block, BlockIndex, BlockedVector, block, blockindex
1+
using BlockArrays:
2+
Block, BlockIndex, BlockedArray, BlockedVector, block, blockedrange, blockindex, mortar
23
using BlockSparseArrays: BlockSparseArrays, BlockIndexVector, GenericBlockIndex
34
using Test: @test, @test_broken, @testset
45

@@ -124,4 +125,36 @@ using Test: @test, @test_broken, @testset
124125
@test a[i1, i2] == [("b", "c") ("b", "d"); ("a", "c") ("a", "d")]
125126
@test a[i] == [("b", "c") ("b", "d"); ("a", "c") ("a", "d")]
126127
@test a[i2, i2] == [("c", "c") ("c", "d"); ("d", "c") ("d", "d")]
128+
129+
r = blockedrange([2, 3])
130+
i = mortar([BlockIndexVector(Block(2), [1]), BlockIndexVector(Block(1), [1, 2])])
131+
# TODO: Check the indices make sense and are in bounds.
132+
@test BlockSparseArrays.blockrange(r, i) == [Block(2), Block(1)]
133+
134+
r = blockedrange([2, 3])
135+
i = mortar([BlockIndexVector(Block(2), ["x"]), BlockIndexVector(Block(1), ["y", "z"])])
136+
# TODO: Check the indices make sense and are in bounds.
137+
@test BlockSparseArrays.blockrange(r, i) == [Block(2), Block(1)]
138+
139+
i = GenericBlockIndex(Block(2), 1)
140+
# TODO: Is this a good definition?
141+
@test Base.to_index(i) === i
142+
143+
r = blockedrange([2, 3])
144+
@test checkindex(Bool, r, GenericBlockIndex(Block(1), 1))
145+
@test checkindex(Bool, r, GenericBlockIndex(Block(1), 2))
146+
@test !checkindex(Bool, r, GenericBlockIndex(Block(1), 3))
147+
@test checkindex(Bool, r, GenericBlockIndex(Block(2), 1))
148+
@test checkindex(Bool, r, GenericBlockIndex(Block(2), 2))
149+
@test checkindex(Bool, r, GenericBlockIndex(Block(2), 3))
150+
@test !checkindex(Bool, r, GenericBlockIndex(Block(2), 4))
151+
@test !checkindex(Bool, r, GenericBlockIndex(Block(3), 1))
152+
153+
a = BlockedArray(randn(5, 5), [2, 3], [2, 3])
154+
i = GenericBlockIndex(Block(1), 1)
155+
@test to_indices(a, (i, i)) == (1, 1)
156+
@test to_indices(a, axes(a), (i, i)) == (1, 1)
157+
i = GenericBlockIndex(Block(2), 2)
158+
@test to_indices(a, (i, i)) == (4, 4)
159+
@test to_indices(a, axes(a), (i, i)) == (4, 4)
127160
end

0 commit comments

Comments
 (0)