1- using BlockArrays: BlockArrays, Block, blockedrange, blocklength
1+ using BlockArrays: BlockArrays, Block, blocklength
22using BlockSparseArrays: eachblockstoredindex
33using Dictionaries: Dictionary
44using GradedArrays: GradedArrays, AbelianGradedArray, AbelianSectorArray,
@@ -216,8 +216,8 @@ using Test: @test, @test_throws, @testset
216216 end
217217end
218218
219- @testset " FusedGradedMatrix Pair constructor" begin
220- m = FusedGradedMatrix ([U1 (0 ) => [ 1.0 2.0 ; 3.0 4.0 ], U1 ( 1 ) => ones (3 , 3 )])
219+ @testset " FusedGradedMatrix sectors/blocks constructor" begin
220+ m = FusedGradedMatrix ([U1 (0 ), U1 ( 1 )], [[ 1.0 2.0 ; 3.0 4.0 ], ones (3 , 3 )])
221221 @test m isa FusedGradedMatrix{Float64}
222222 @test data (m[Block (1 , 1 )]) == [1.0 2.0 ; 3.0 4.0 ]
223223 @test data (m[Block (2 , 2 )]) == ones (3 , 3 )
226226 # dimension `2j + 1`, so `Block(k, k)` has size
227227 # `(sectorlength × datalength)^2`.
228228 m_su2 = FusedGradedMatrix (
229- [
230- SU2 (0 ) => [1.0 ;;],
231- SU2 (1 // 2 ) => [1.0 2.0 ; 3.0 4.0 ],
232- SU2 (1 ) => Matrix {Float64} (LinearAlgebra. I, 3 , 3 ),
233- ]
229+ [SU2 (0 ), SU2 (1 // 2 ), SU2 (1 )],
230+ [[1.0 ;;], [1.0 2.0 ; 3.0 4.0 ], Matrix {Float64} (LinearAlgebra. I, 3 , 3 )]
234231 )
235232 @test m_su2 isa FusedGradedMatrix{Float64, Matrix{Float64}, SU2}
236233 @test collect (keys (m_su2. blocks)) == [SU2 (0 ), SU2 (1 // 2 ), SU2 (1 )]
@@ -242,75 +239,51 @@ end
242239
243240@testset " FusedGradedMatrix * FusedGradedMatrix" begin
244241 @testset " U1 (abelian)" begin
245- a = FusedGradedMatrix ([U1 (0 ) => [ 2.0 ;;], U1 ( 1 ) => [1.0 2.0 ; 3.0 4.0 ]])
246- b = FusedGradedMatrix ([U1 (0 ) => [ 3.0 ;;], U1 ( 1 ) => [0.0 1.0 ; 1.0 0.0 ]])
242+ a = FusedGradedMatrix ([U1 (0 ), U1 ( 1 )], [[ 2.0 ;;], [1.0 2.0 ; 3.0 4.0 ]])
243+ b = FusedGradedMatrix ([U1 (0 ), U1 ( 1 )], [[ 3.0 ;;], [0.0 1.0 ; 1.0 0.0 ]])
247244 c = a * b
248245 @test collect (keys (c. blocks)) == [U1 (0 ), U1 (1 )]
249246 @test data (c[Block (1 , 1 )]) == [6.0 ;;]
250247 @test data (c[Block (2 , 2 )]) == [1.0 2.0 ; 3.0 4.0 ] * [0.0 1.0 ; 1.0 0.0 ]
251248 end
252249 @testset " SU2 (non-abelian)" begin
253- a = FusedGradedMatrix ([SU2 (0 ) => [ 2.0 ;;] , SU2 (1 // 2 ) => [1.0 2.0 ; 3.0 4.0 ]])
254- b = FusedGradedMatrix ([SU2 (0 ) => [ 3.0 ;;] , SU2 (1 // 2 ) => [0.0 1.0 ; 1.0 0.0 ]])
250+ a = FusedGradedMatrix ([SU2 (0 ), SU2 (1 // 2 )], [[ 2.0 ;;], [1.0 2.0 ; 3.0 4.0 ]])
251+ b = FusedGradedMatrix ([SU2 (0 ), SU2 (1 // 2 )], [[ 3.0 ;;], [0.0 1.0 ; 1.0 0.0 ]])
255252 c = a * b
256253 @test collect (keys (c. blocks)) == [SU2 (0 ), SU2 (1 // 2 )]
257254 @test data (c[Block (1 , 1 )]) == [6.0 ;;]
258255 @test data (c[Block (2 , 2 )]) == [1.0 2.0 ; 3.0 4.0 ] * [0.0 1.0 ; 1.0 0.0 ]
259256 end
260257 @testset " mismatched sectors throws" begin
261- a = FusedGradedMatrix ([U1 (0 ) => [ 2.0 ;;], U1 ( 1 ) => [1.0 2.0 ; 3.0 4.0 ]])
262- b = FusedGradedMatrix ([U1 (0 ) => [3.0 ;;]])
258+ a = FusedGradedMatrix ([U1 (0 ), U1 ( 1 )], [[ 2.0 ;;], [1.0 2.0 ; 3.0 4.0 ]])
259+ b = FusedGradedMatrix ([U1 (0 )], [ [3.0 ;;]])
263260 @test_throws DimensionMismatch a * b
264261 end
265262end
266263
267264@testset " FusedGradedMatrix undef constructor" begin
268265 sectors = [U1 (0 ), U1 (1 )]
269- cod_bls = [2 , 3 ]
270- dom_bls = [1 , 2 ]
266+ cod = Dictionary {U1, Int} (sectors, [2 , 3 ])
267+ dom = Dictionary {U1, Int} (sectors, [1 , 2 ])
271268
272- @testset " Convenience constructor (defaults D = Matrix{T}) " begin
273- m = FusedGradedMatrix {Float64} (undef, sectors, cod_bls, dom_bls )
269+ @testset " Default D = Matrix{T}" begin
270+ m = FusedGradedMatrix {Float64} (undef, cod, dom )
274271 @test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
275272 @test length (m. blocks) == 2
276273 @test collect (keys (m. blocks)) == sectors
277274 @test size (m. blocks[U1 (0 )]) == (2 , 1 )
278275 @test size (m. blocks[U1 (1 )]) == (3 , 2 )
279276 end
280277
281- @testset " Fully parameterized constructor" begin
282- m = FusedGradedMatrix {Float64, Matrix{Float64}, U1} (
283- undef, sectors, (blockedrange (cod_bls), blockedrange (dom_bls))
284- )
278+ @testset " Fully parameterized" begin
279+ m = FusedGradedMatrix {Float64, Matrix{Float64}, U1} (undef, cod, dom)
285280 @test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
286281 @test size (m. blocks[U1 (0 )]) == (2 , 1 )
287282 end
288283
289- @testset " Tuple BlockedOneTo form" begin
290- m = FusedGradedMatrix {Float64} (
291- undef, sectors, (blockedrange ([2 , 3 ]), blockedrange ([1 , 2 ]))
292- )
293- @test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
294- @test size (m. blocks[U1 (0 )]) == (2 , 1 )
295- @test size (m. blocks[U1 (1 )]) == (3 , 2 )
296- end
297-
298- @testset " Rejects mismatched lengths" begin
299- @test_throws Exception FusedGradedMatrix {Float64} (
300- undef, sectors, cod_bls, [1 ]
301- )
302- end
303-
304284 @testset " Rejects unsorted sectors" begin
305- @test_throws ArgumentError FusedGradedMatrix {Float64} (
306- undef, [U1 (1 ), U1 (0 )], cod_bls, dom_bls
307- )
308- end
309-
310- @testset " Rejects non-unique sectors" begin
311- @test_throws ArgumentError FusedGradedMatrix {Float64} (
312- undef, [U1 (0 ), U1 (0 )], [2 , 3 ], [1 , 2 ]
313- )
285+ cod_bad = Dictionary {U1, Int} ([U1 (1 ), U1 (0 )], [2 , 3 ])
286+ @test_throws ArgumentError FusedGradedMatrix {Float64} (undef, cod_bad, dom)
314287 end
315288end
316289
0 commit comments