Skip to content

Commit 8e7f61b

Browse files
authored
[NDTensors] Fix isempty(::Tensor) (#1401)
1 parent ff6a871 commit 8e7f61b

File tree

7 files changed

+49
-155
lines changed

7 files changed

+49
-155
lines changed

Checklists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ Checklist for Tagging a New Release
1414
automatically (if you see a notice about "Trigger TagBot Issue"
1515
it does not mean that TagBot isn't working or has an issue, it
1616
is just literally a Github issue used to trigger TagBot to run)
17-
- TagBot helpfully explains the differences from the previous
18-
versions in the Github version entry. This can be useful for
19-
updating the NEWS.md file.
2017

2118
Checklist for Updating the Version of Documenter.jl Used
2219
----------------------------------------------------------

NDTensors/NEWS.md

Lines changed: 0 additions & 143 deletions
This file was deleted.

NDTensors/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NDTensors"
22
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
33
authors = ["Matthew Fishman <[email protected]>"]
4-
version = "0.3.1"
4+
version = "0.3.2"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

NDTensors/src/tensor/tensor.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ array(T::Tensor) = array(dense(T))
277277
matrix(T::Tensor{<:Number,2}) = array(T)
278278
vector(T::Tensor{<:Number,1}) = array(T)
279279

280-
isempty(T::Tensor) = isempty(storage(T))
281-
282280
#
283281
# Helper functions for BlockSparse-type storage
284282
#

NDTensors/test/test_blocksparse.jl

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
@eval module $(gensym())
2-
using NDTensors
3-
using LinearAlgebra: Hermitian, exp, svd
4-
using Test: @testset, @test, @test_throws
52
using GPUArraysCore: @allowscalar
3+
using LinearAlgebra: Hermitian, exp, norm, svd
4+
using NDTensors:
5+
NDTensors,
6+
BlockSparseTensor,
7+
array,
8+
blockdims,
9+
blockoffsets,
10+
blockview,
11+
data,
12+
dense,
13+
dims,
14+
eachnzblock,
15+
inds,
16+
isblocknz,
17+
nnz,
18+
nnzblocks,
19+
randomBlockSparseTensor,
20+
store,
21+
storage
622
include("NDTensorsTestUtils/NDTensorsTestUtils.jl")
723
using .NDTensorsTestUtils: default_rtol, devices_list, is_supported_eltype
24+
using Random: randn!
25+
using Test: @test, @test_throws, @testset
826

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

2745
@test blockdims(A, (1, 2)) == (2, 5)
2846
@test blockdims(A, (2, 1)) == (3, 4)
47+
@test !isempty(A)
2948
@test nnzblocks(A) == 2
3049
@test nnz(A) == 2 * 5 + 3 * 4
3150
@test inds(A) == ([2, 3], [4, 5])
@@ -102,6 +121,30 @@ using .NDTensorsTestUtils: default_rtol, devices_list, is_supported_eltype
102121
@test conj(data(store(A))) == data(store(conj(A)))
103122
@test typeof(conj(A)) <: BlockSparseTensor
104123

124+
@testset "No blocks" begin
125+
T = dev(BlockSparseTensor{elt}(Tuple{Int,Int}[], [2, 2], [2, 2]))
126+
@test nnzblocks(T) == 0
127+
@test size(T) == (4, 4)
128+
@test length(T) == 16
129+
@test !isempty(T)
130+
@test isempty(storage(T))
131+
@test nnz(T) == 0
132+
@test eltype(T) == elt
133+
@test norm(T) == 0
134+
end
135+
136+
@testset "Empty" begin
137+
T = dev(BlockSparseTensor{elt}(Tuple{Int,Int}[], Int[], Int[]))
138+
@test nnzblocks(T) == 0
139+
@test size(T) == (0, 0)
140+
@test length(T) == 0
141+
@test isempty(T)
142+
@test isempty(storage(T))
143+
@test nnz(T) == 0
144+
@test eltype(T) == elt
145+
@test norm(T) == 0
146+
end
147+
105148
@testset "Random constructor" begin
106149
T = dev(randomBlockSparseTensor(elt, [(1, 1), (2, 2)], ([2, 2], [2, 2])))
107150
@test nnzblocks(T) == 2

docs/src/UpgradeGuide_0.1_to_0.2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The main breaking changes in ITensor.jl v0.2 involve changes to the `ITensor`, `
66

77
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.
88

9-
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).
9+
For a more comprehensive list of changes, see the [commit history on Github](https://github.com/ITensor/ITensors.jl/commits/main).
1010

1111
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/).
1212

docs/src/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ Development of ITensor is supported by the Flatiron Institute, a division of the
3535

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

4140
## Installation
4241

0 commit comments

Comments
 (0)