Skip to content

Commit

Permalink
[NDTensors] Fix isempty(::Tensor) (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Apr 29, 2024
1 parent ff6a871 commit 8e7f61b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 155 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: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.3.1"
version = "0.3.2"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
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

2 comments on commit 8e7f61b

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=NDTensors

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105784

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a NDTensors-v0.3.2 -m "<description of version>" 8e7f61b57e8f5d753b86f9f8bc815bfaaa6e7c83
git push origin NDTensors-v0.3.2

Please sign in to comment.