Skip to content

Define zeros #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GradedArrays"
uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.2"
version = "0.2.3"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand Down
6 changes: 6 additions & 0 deletions src/gradedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
return similar_blocksparse(a, elt, axes)
end

function Base.zeros(

Check warning on line 90 in src/gradedarray.jl

View check run for this annotation

Codecov / codecov/patch

src/gradedarray.jl#L90

Added line #L90 was not covered by tests
elt::Type, ax::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}}
)
return BlockSparseArray{elt}(undef, ax)

Check warning on line 93 in src/gradedarray.jl

View check run for this annotation

Codecov / codecov/patch

src/gradedarray.jl#L93

Added line #L93 was not covered by tests
end

function getindex_blocksparse(a::AbstractArray, I::AbstractUnitRange...)
a′ = similar(a, only.(axes.(I))...)
a′ .= a
Expand Down
21 changes: 18 additions & 3 deletions test/test_gradedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,24 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
@test 2 * Array(a) == b
end

d1 = gradedrange([U1(0) => 2, U1(1) => 2])
d2 = gradedrange([U1(0) => 2, U1(1) => 2])
a = randn_blockdiagonal(elt, (d1, d2, d1, d2))
r = gradedrange([U1(0) => 2, U1(1) => 2])
a = zeros(r, r, r, r)
@test a isa BlockSparseArray{Float64}
@test eltype(a) === Float64
@test size(a) == (4, 4, 4, 4)
@test iszero(a)
@test iszero(blockstoredlength(a))

r = gradedrange([U1(0) => 2, U1(1) => 2])
a = zeros(elt, r, r, r, r)
@test a isa BlockSparseArray{elt}
@test eltype(a) === elt
@test size(a) == (4, 4, 4, 4)
@test iszero(a)
@test iszero(blockstoredlength(a))

r = gradedrange([U1(0) => 2, U1(1) => 2])
a = randn_blockdiagonal(elt, (r, r, r, r))
b = similar(a, ComplexF64)
@test b isa BlockSparseArray{ComplexF64}
@test eltype(b) === ComplexF64
Expand Down
Loading