Skip to content

Commit 443ac70

Browse files
committed
Fix indexing order, test blockwise slicing
1 parent 0512647 commit 443ac70

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/test_blocksparsearrays.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Adapt: adapt
22
using BlockArrays: Block, BlockRange, mortar
33
using BlockSparseArrays:
4-
BlockSparseArray, BlockSparseMatrix, blockrange, blocksparse, blocktype
4+
BlockIndexVector, BlockSparseArray, BlockSparseMatrix, blockrange, blocksparse, blocktype
55
using FillArrays: Eye, SquareEye
66
using JLArrays: JLArray
7-
using KroneckerArrays: KroneckerArray, , ×
7+
using KroneckerArrays: KroneckerArray, , ×, arg1, arg2
88
using LinearAlgebra: norm
99
using MatrixAlgebraKit: svd_compact
1010
using Test: @test, @test_broken, @testset
@@ -50,6 +50,16 @@ arrayts = (Array, JLArray)
5050
@test a[Block(2, 2)[(:) × (2:3), (:) × (2:3)]] == a[Block(2, 2)][(:) × (2:3), (:) × (2:3)]
5151
@test_broken a[Block(2, 2)][(1:2) × (2:3), (:) × (2:3)]
5252

53+
# Blockwise slicing, shows up in truncated block sparse matrix factorizations.
54+
I1 = BlockIndexVector(Block(1), Base.Slice(Base.OneTo(2)) × [1])
55+
I2 = BlockIndexVector(Block(2), Base.Slice(Base.OneTo(3)) × [1, 3])
56+
I = [I1, I2]
57+
b = a[I, I]
58+
@test b[Block(1, 1)] == a[Block(1, 1)[(1:2) × [1], (1:2) × [1]]]
59+
@test iszero(b[Block(2, 1)])
60+
@test iszero(b[Block(1, 2)])
61+
@test b[Block(2, 2)] == a[Block(2, 2)[(1:3) × [1, 3], (1:3) × [1, 3]]]
62+
5363
# Slicing
5464
r = blockrange([2 × 2, 3 × 3])
5565
d = Dict(
@@ -161,6 +171,20 @@ end
161171
@test a[Block(2, 2)[(:) × (2:3), (:) × (2:3)]] == a[Block(2, 2)][(:) × (2:3), (:) × (2:3)]
162172
@test_broken a[Block(2, 2)][(1:2) × (2:3), (:) × (2:3)]
163173

174+
# Blockwise slicing, shows up in truncated block sparse matrix factorizations.
175+
I1 = BlockIndexVector(Block(1), Base.Slice(Base.OneTo(2)) × [1])
176+
I2 = BlockIndexVector(Block(2), Base.Slice(Base.OneTo(3)) × [1, 3])
177+
I = [I1, I2]
178+
b = a[I, I]
179+
@test b[Block(1, 1)] == a[Block(1, 1)[(1:2) × [1], (1:2) × [1]]]
180+
@test arg1(b[Block(1, 1)]) isa Eye
181+
@test iszero(b[Block(2, 1)])
182+
@test arg1(b[Block(2, 1)]) isa Eye
183+
@test iszero(b[Block(1, 2)])
184+
@test arg1(b[Block(1, 2)]) isa Eye
185+
@test b[Block(2, 2)] == a[Block(2, 2)[(1:3) × [1, 3], (1:3) × [1, 3]]]
186+
@test arg1(b[Block(2, 2)]) isa Eye
187+
164188
# Slicing
165189
r = blockrange([2 × 2, 3 × 3])
166190
d = Dict(

0 commit comments

Comments
 (0)