@@ -48,12 +48,39 @@ include("TestBlockSparseArraysUtils.jl")
4848 @test block_nstored (a) == 2
4949 @test nstored (a) == 2 * 4 + 3 * 3
5050
51+ b = similar (a, complex (elt))
52+ @test eltype (b) == complex (eltype (a))
53+ @test iszero (b)
54+ @test block_nstored (b) == 0
55+ @test nstored (b) == 0
56+ @test size (b) == size (a)
57+ @test blocksize (b) == blocksize (a)
58+
59+ b = copy (a)
60+ b[1 , 1 ] = 11
61+ @test b[1 , 1 ] == 11
62+ @test a[1 , 1 ] ≠ 11
63+
64+ b = copy (a)
65+ b .*= 2
66+ @test b ≈ 2 a
67+
68+ b = copy (a)
69+ b ./= 2
70+ @test b ≈ a / 2
71+
5172 b = 2 * a
5273 @test Array (b) ≈ 2 * Array (a)
5374 @test eltype (b) == elt
5475 @test block_nstored (b) == 2
5576 @test nstored (b) == 2 * 4 + 3 * 3
5677
78+ b = (2 + 3im ) * a
79+ @test Array (b) ≈ (2 + 3im ) * Array (a)
80+ @test eltype (b) == complex (elt)
81+ @test block_nstored (b) == 2
82+ @test nstored (b) == 2 * 4 + 3 * 3
83+
5784 b = a + a
5885 @test Array (b) ≈ 2 * Array (a)
5986 @test eltype (b) == elt
@@ -78,8 +105,75 @@ include("TestBlockSparseArraysUtils.jl")
78105 b = map (x -> 2 x, a)
79106 @test Array (b) ≈ 2 * Array (a)
80107 @test eltype (b) == elt
108+ @test size (b) == size (a)
109+ @test blocksize (b) == (2 , 2 )
81110 @test block_nstored (b) == 2
82111 @test nstored (b) == 2 * 4 + 3 * 3
112+
113+ b = a[[Block (2 ), Block (1 )], [Block (2 ), Block (1 )]]
114+ @test b[Block (1 , 1 )] == a[Block (2 , 2 )]
115+ @test b[Block (1 , 2 )] == a[Block (2 , 1 )]
116+ @test b[Block (2 , 1 )] == a[Block (1 , 2 )]
117+ @test b[Block (2 , 2 )] == a[Block (1 , 1 )]
118+ @test size (b) == size (a)
119+ @test blocksize (b) == (2 , 2 )
120+ @test nstored (b) == nstored (a)
121+ @test block_nstored (b) == 2
122+
123+ b = a[Block (1 ): Block (2 ), Block (1 ): Block (2 )]
124+ @test b == a
125+ @test size (b) == size (a)
126+ @test blocksize (b) == (2 , 2 )
127+ @test nstored (b) == nstored (a)
128+ @test block_nstored (b) == 2
129+
130+ b = a[Block (1 ): Block (1 ), Block (1 ): Block (2 )]
131+ @test b == Array (a)[1 : 2 , 1 : end ]
132+ @test b[Block (1 , 1 )] == a[Block (1 , 1 )]
133+ @test b[Block (1 , 2 )] == a[Block (1 , 2 )]
134+ @test size (b) == (2 , 7 )
135+ @test blocksize (b) == (1 , 2 )
136+ @test nstored (b) == nstored (a[Block (1 , 2 )])
137+ @test block_nstored (b) == 1
138+
139+ b = a[2 : 4 , 2 : 4 ]
140+ @test b == Array (a)[2 : 4 , 2 : 4 ]
141+ @test size (b) == (3 , 3 )
142+ @test blocksize (b) == (2 , 2 )
143+ @test nstored (b) == 1 * 1 + 2 * 2
144+ @test block_nstored (b) == 2
145+
146+ b = a[Block (2 , 1 )[1 : 2 , 2 : 3 ]]
147+ @test b == Array (a)[3 : 4 , 2 : 3 ]
148+ @test size (b) == (2 , 2 )
149+ @test blocksize (b) == (1 , 1 )
150+ @test nstored (b) == 2 * 2
151+ @test block_nstored (b) == 1
152+
153+ # # Broken, need to fix.
154+
155+ @test_broken a[Block (1 ), Block (1 ): Block (2 )]
156+
157+ # This is outputting only zero blocks.
158+ b = a[Block (2 ): Block (2 ), Block (1 ): Block (2 )]
159+ @test_broken block_nstored (b) == 1
160+ @test_broken b == Array (a)[3 : 5 , 1 : end ]
161+
162+ b = a'
163+ @test_broken block_nstored (b) == 2
164+
165+ b = transpose (a)
166+ @test_broken block_nstored (b) == 2
167+
168+ b = copy (a)
169+ x = randn (size (@view (a[Block (2 , 2 )])))
170+ b[Block (2 ), Block (2 )] = x
171+ @test_broken b[Block (2 , 2 )] == x
172+
173+ # Doesnt' set the block
174+ b = copy (a)
175+ b[Block (1 , 1 )] .= 1
176+ @test_broken b[1 , 1 ] == trues (size (@view (b[1 , 1 ])))
83177 end
84178 @testset " LinearAlgebra" begin
85179 a1 = BlockSparseArray {elt} ([2 , 3 ], [2 , 3 ])
0 commit comments