Skip to content

Commit

Permalink
[NDTensors] Fix isempty
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Apr 29, 2024
1 parent ff6a871 commit 309ea03
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 154 deletions.
3 changes: 0 additions & 3 deletions Checklists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ Checklist for Tagging a New Release
automatically (if you see a notice about "Trigger TagBot Issue"
it does not mean that TagBot isn't working or has an issue, it
is just literally a Github issue used to trigger TagBot to run)
- TagBot helpfully explains the differences from the previous
versions in the Github version entry. This can be useful for
updating the NEWS.md file.

Checklist for Updating the Version of Documenter.jl Used
----------------------------------------------------------
Expand Down
143 changes: 0 additions & 143 deletions NDTensors/NEWS.md

This file was deleted.

2 changes: 0 additions & 2 deletions NDTensors/src/tensor/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ array(T::Tensor) = array(dense(T))
matrix(T::Tensor{<:Number,2}) = array(T)
vector(T::Tensor{<:Number,1}) = array(T)

isempty(T::Tensor) = isempty(storage(T))

#
# Helper functions for BlockSparse-type storage
#
Expand Down
49 changes: 46 additions & 3 deletions NDTensors/test/test_blocksparse.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
@eval module $(gensym())
using NDTensors
using LinearAlgebra: Hermitian, exp, svd
using Test: @testset, @test, @test_throws
using GPUArraysCore: @allowscalar
using LinearAlgebra: Hermitian, exp, norm, svd
using NDTensors:
NDTensors,
BlockSparseTensor,
array,
blockdims,
blockoffsets,
blockview,
data,
dense,
dims,
eachnzblock,
inds,
isblocknz,
nnz,
nnzblocks,
randomBlockSparseTensor,
store,
storage
include("NDTensorsTestUtils/NDTensorsTestUtils.jl")
using .NDTensorsTestUtils: default_rtol, devices_list, is_supported_eltype
using Random: randn!
using Test: @test, @test_throws, @testset

@testset "BlockSparseTensor basic functionality" begin
C = nothing
Expand All @@ -26,6 +44,7 @@ using .NDTensorsTestUtils: default_rtol, devices_list, is_supported_eltype

@test blockdims(A, (1, 2)) == (2, 5)
@test blockdims(A, (2, 1)) == (3, 4)
@test !isempty(A)
@test nnzblocks(A) == 2
@test nnz(A) == 2 * 5 + 3 * 4
@test inds(A) == ([2, 3], [4, 5])
Expand Down Expand Up @@ -102,6 +121,30 @@ using .NDTensorsTestUtils: default_rtol, devices_list, is_supported_eltype
@test conj(data(store(A))) == data(store(conj(A)))
@test typeof(conj(A)) <: BlockSparseTensor

@testset "No blocks" begin
T = dev(BlockSparseTensor{elt}(Tuple{Int,Int}[], [2, 2], [2, 2]))
@test nnzblocks(T) == 0
@test size(T) == (4, 4)
@test length(T) == 16
@test !isempty(T)
@test isempty(storage(T))
@test nnz(T) == 0
@test eltype(T) == elt
@test norm(T) == 0
end

@testset "Empty" begin
T = dev(BlockSparseTensor{elt}(Tuple{Int,Int}[], Int[], Int[]))
@test nnzblocks(T) == 0
@test size(T) == (0, 0)
@test length(T) == 0
@test isempty(T)
@test isempty(storage(T))
@test nnz(T) == 0
@test eltype(T) == elt
@test norm(T) == 0
end

@testset "Random constructor" begin
T = dev(randomBlockSparseTensor(elt, [(1, 1), (2, 2)], ([2, 2], [2, 2])))
@test nnzblocks(T) == 2
Expand Down
2 changes: 1 addition & 1 deletion docs/src/UpgradeGuide_0.1_to_0.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The main breaking changes in ITensor.jl v0.2 involve changes to the `ITensor`, `

In addition, we have moved development of NDTensors.jl into ITensors.jl to simplify the development process until NDTensors is more stable and can be a standalone package. Again, see below for more details.

For a more comprehensive list of changes, see the [change log](https://github.com/ITensor/ITensors.jl/blob/main/NEWS.md) and the [commit history on Github](https://github.com/ITensor/ITensors.jl/commits/main).
For a more comprehensive list of changes, see the [commit history on Github](https://github.com/ITensor/ITensors.jl/commits/main).

If you have issues upgrading, please reach out by [raising an issue on Github](https://github.com/ITensor/ITensors.jl/issues/new) or asking a question on the [ITensor support forum](http://itensor.org/support/).

Expand Down
3 changes: 1 addition & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Development of ITensor is supported by the Flatiron Institute, a division of the

- Jun 09, 2021: ITensors.jl v0.2 has been released, with a few breaking changes as well as a variety of bug fixes
and new features. Take a look at the [upgrade guide](https://itensor.github.io/ITensors.jl/stable/UpgradeGuide_0.1_to_0.2.html)
for help upgrading your code as well as the [change log](https://github.com/ITensor/ITensors.jl/blob/main/NEWS.md)
for a comprehensive list of changes.
for help upgrading your code.

## Installation

Expand Down

0 comments on commit 309ea03

Please sign in to comment.