Skip to content

Commit 9ad40f8

Browse files
authored
Define zeros (#9)
1 parent 8714abd commit 9ad40f8

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GradedArrays"
22
uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.2"
4+
version = "0.2.3"
55

66
[deps]
77
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"

src/gradedarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ function Base.similar(
8787
return similar_blocksparse(a, elt, axes)
8888
end
8989

90+
function Base.zeros(
91+
elt::Type, ax::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}}
92+
)
93+
return BlockSparseArray{elt}(undef, ax)
94+
end
95+
9096
function getindex_blocksparse(a::AbstractArray, I::AbstractUnitRange...)
9197
a′ = similar(a, only.(axes.(I))...)
9298
a′ .= a

test/test_gradedarray.jl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,24 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
5757
@test 2 * Array(a) == b
5858
end
5959

60-
d1 = gradedrange([U1(0) => 2, U1(1) => 2])
61-
d2 = gradedrange([U1(0) => 2, U1(1) => 2])
62-
a = randn_blockdiagonal(elt, (d1, d2, d1, d2))
60+
r = gradedrange([U1(0) => 2, U1(1) => 2])
61+
a = zeros(r, r, r, r)
62+
@test a isa BlockSparseArray{Float64}
63+
@test eltype(a) === Float64
64+
@test size(a) == (4, 4, 4, 4)
65+
@test iszero(a)
66+
@test iszero(blockstoredlength(a))
67+
68+
r = gradedrange([U1(0) => 2, U1(1) => 2])
69+
a = zeros(elt, r, r, r, r)
70+
@test a isa BlockSparseArray{elt}
71+
@test eltype(a) === elt
72+
@test size(a) == (4, 4, 4, 4)
73+
@test iszero(a)
74+
@test iszero(blockstoredlength(a))
75+
76+
r = gradedrange([U1(0) => 2, U1(1) => 2])
77+
a = randn_blockdiagonal(elt, (r, r, r, r))
6378
b = similar(a, ComplexF64)
6479
@test b isa BlockSparseArray{ComplexF64}
6580
@test eltype(b) === ComplexF64

0 commit comments

Comments
 (0)