Skip to content

Commit 74bd950

Browse files
authored
Make similar with graded axes more generic (#48)
1 parent e9a6208 commit 74bd950

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.17"
4+
version = "0.2.18"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module BlockSparseArraysGradedUnitRangesExt
22

33
using BlockSparseArrays: AnyAbstractBlockSparseArray, BlockSparseArray, blocktype
44
using GradedUnitRanges: AbstractGradedUnitRange
5-
using TypeParameterAccessors: set_eltype, set_ndims, unwrap_array_type
5+
using TypeParameterAccessors: similartype, unwrap_array_type
66

77
# A block spare array similar to the input (dense) array.
88
# TODO: Make `BlockSparseArrays.blocksparse_similar` more general and use that,
@@ -15,9 +15,7 @@ function similar_blocksparse(
1515
# TODO: Probably need to unwrap the type of `a` in certain cases
1616
# to make a proper block type.
1717
return BlockSparseArray{
18-
elt,
19-
length(axes),
20-
set_eltype(set_ndims(unwrap_array_type(blocktype(a)), length(axes)), elt),
18+
elt,length(axes),similartype(unwrap_array_type(blocktype(a)), elt, axes)
2119
}(
2220
axes
2321
)

test/test_gradedunitrangesext.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
350350
@test b[Block(1)] == a1
351351
@test iszero(b[Block(2)])
352352
@test all(GradedUnitRanges.space_isequal.(axes(b), (r,)))
353+
354+
# Regression test for BitArray
355+
r = gradedrange([U1(0) => 2, U1(1) => 3])
356+
a1 = trues(2, 2)
357+
a2 = trues(3, 3)
358+
a = cat(a1, a2; dims=(1, 2))
359+
b = a[r, dual(r)]
360+
@test eltype(b) === Bool
361+
@test b isa BlockSparseMatrix{Bool}
362+
@test blockstoredlength(b) == 2
363+
@test b[Block(1, 1)] == a1
364+
@test iszero(b[Block(2, 1)])
365+
@test iszero(b[Block(1, 2)])
366+
@test b[Block(2, 2)] == a2
367+
@test all(GradedUnitRanges.space_isequal.(axes(b), (r, dual(r))))
353368
end
354369
end
355370
end

0 commit comments

Comments
 (0)