|
1 |
| -using BlockArrays: Block, BlockIndex, BlockedVector, block, blockindex |
| 1 | +using BlockArrays: |
| 2 | + Block, BlockIndex, BlockedArray, BlockedVector, block, blockedrange, blockindex, mortar |
2 | 3 | using BlockSparseArrays: BlockSparseArrays, BlockIndexVector, GenericBlockIndex
|
3 | 4 | using Test: @test, @test_broken, @testset
|
4 | 5 |
|
@@ -124,4 +125,36 @@ using Test: @test, @test_broken, @testset
|
124 | 125 | @test a[i1, i2] == [("b", "c") ("b", "d"); ("a", "c") ("a", "d")]
|
125 | 126 | @test a[i] == [("b", "c") ("b", "d"); ("a", "c") ("a", "d")]
|
126 | 127 | @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) |
127 | 160 | end
|
0 commit comments