Skip to content

Commit 090c202

Browse files
committed
Add test for converting dense to block sparse with graded unit ranges
1 parent 36cd30a commit 090c202

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/test_gradedunitrangesext.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Test: @test, @testset
33
using BlockArrays:
44
AbstractBlockArray, Block, BlockedOneTo, blockedrange, blocklengths, blocksize
5-
using BlockSparseArrays: BlockSparseArray, blockstoredlength
5+
using BlockSparseArrays: BlockSparseArray, BlockSparseMatrix, blockstoredlength
66
using GradedUnitRanges:
77
GradedUnitRanges,
88
GradedOneTo,
@@ -318,5 +318,20 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
318318
@test Array(a1' * a2) Array(a1') * Array(a2)
319319
@test Array(a1 * a2') Array(a1) * Array(a2')
320320
end
321+
@testset "Construct from dense" begin
322+
r = gradedrange([U1(0) => 2, U1(1) => 3])
323+
a1 = randn(elt, 2, 2)
324+
a2 = randn(elt, 3, 3)
325+
a = cat(a1, a2; dims=(1, 2))
326+
b = a[r, dual(r)]
327+
@test eltype(b) === elt
328+
@test b isa BlockSpareMatrix{elt}
329+
@test blockstoredlength(b) == 2
330+
@test b[Block(1, 1)] == a1
331+
@test iszero(b[Block(2, 1)])
332+
@test iszero(b[Block(1, 2)])
333+
@test b[Block(2, 2)] == a2
334+
@test all(GradedUnitRanges.space_isequal.(axes(b), (r, dual(r))))
335+
end
321336
end
322337
end

0 commit comments

Comments
 (0)