Skip to content

Commit

Permalink
[NDTensors] [ITensors] Overload SparseArrays.nnz (#1582)
Browse files Browse the repository at this point in the history
* [NDTensors] [ITensors] Overload SparseArrays.nnz

* [NDTensors] Bump to v0.3.65

* [ITensors] Bump to v0.7.6
  • Loading branch information
mtfishman authored Nov 14, 2024
1 parent 57994ff commit 2e5da07
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 14 deletions.
8 changes: 4 additions & 4 deletions 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.64"
version = "0.3.65"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down Expand Up @@ -73,15 +73,15 @@ HDF5 = "0.14, 0.15, 0.16, 0.17"
HalfIntegers = "1"
InlineStrings = "1"
JLArrays = "0.1, 0.2"
LinearAlgebra = "<0.0.1, 1.6"
LinearAlgebra = "<0.0.1, 1.10"
MacroTools = "0.5"
MappedArrays = "0.4"
Metal = "1"
Octavian = "0.3"
PackageExtensionCompat = "1"
Random = "<0.0.1, 1.6"
Random = "<0.0.1, 1.10"
SimpleTraits = "0.9.4"
SparseArrays = "<0.0.1, 1.6"
SparseArrays = "<0.0.1, 1.10"
SplitApplyCombine = "1.2.2"
StaticArrays = "0.12, 1.0"
Strided = "2"
Expand Down
4 changes: 3 additions & 1 deletion NDTensors/src/blocksparse/blockoffsets.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SparseArrays: SparseArrays

#
# BlockOffsets
#
Expand Down Expand Up @@ -57,7 +59,7 @@ function offset(bofs::BlockOffsets{N}, block::Block{N}) where {N}
return bofs[block]
end

function nnz(bofs::BlockOffsets, inds)
function SparseArrays.nnz(bofs::BlockOffsets, inds)
_nnz = 0
nnzblocks(bofs) == 0 && return _nnz
for block in eachnzblock(bofs)
Expand Down
1 change: 1 addition & 0 deletions NDTensors/src/blocksparse/blocksparsetensor.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SparseArrays: nnz
using .TypeParameterAccessors: similartype

#
Expand Down
1 change: 1 addition & 0 deletions NDTensors/src/blocksparse/similar.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SparseArrays: nnz
using .TypeParameterAccessors: similartype

# NDTensors.similar
Expand Down
2 changes: 2 additions & 0 deletions NDTensors/src/dense/densetensor.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SparseArrays: nnz

#
# DenseTensor (Tensor using Dense storage)
#
Expand Down
2 changes: 2 additions & 0 deletions NDTensors/src/dense/tensoralgebra/contract.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SparseArrays: nnz

function contraction_output(tensor1::DenseTensor, tensor2::DenseTensor, indsR)
tensortypeR = contraction_output_type(typeof(tensor1), typeof(tensor2), indsR)
return NDTensors.similar(tensortypeR, indsR)
Expand Down
3 changes: 2 additions & 1 deletion NDTensors/src/empty/empty.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SparseArrays: SparseArrays
using .TypeParameterAccessors: TypeParameterAccessors, set_eltype, similartype

#
Expand Down Expand Up @@ -66,7 +67,7 @@ isempty(::EmptyStorage) = true

nnzblocks(::EmptyStorage) = 0

nnz(::EmptyStorage) = 0
SparseArrays.nnz(::EmptyStorage) = 0

function conj(::AllowAlias, S::EmptyStorage)
return S
Expand Down
4 changes: 3 additions & 1 deletion NDTensors/src/tensor/tensor.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SparseArrays: SparseArrays, nnz

"""
Tensor{StoreT,IndsT}
Expand Down Expand Up @@ -307,7 +309,7 @@ eachnzblock(T::Tensor) = eachnzblock(storage(T))

blockoffsets(T::Tensor) = blockoffsets(storage(T))
nnzblocks(T::Tensor) = nnzblocks(storage(T))
nnz(T::Tensor) = nnz(storage(T))
SparseArrays.nnz(T::Tensor) = nnz(storage(T))
nblocks(T::Tensor) = nblocks(inds(T))
blockdims(T::Tensor, block) = blockdims(inds(T), block)
blockdim(T::Tensor, block) = blockdim(inds(T), block)
Expand Down
4 changes: 3 additions & 1 deletion NDTensors/src/tensorstorage/tensorstorage.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SparseArrays: SparseArrays

abstract type TensorStorage{ElT} <: AbstractVector{ElT} end

data(S::TensorStorage) = S.data
Expand Down Expand Up @@ -98,6 +100,6 @@ nzblocks(T::TensorStorage) = nzblocks(blockoffsets(T))
eachnzblock(T::TensorStorage) = eachnzblock(blockoffsets(T))

nnzblocks(S::TensorStorage) = length(blockoffsets(S))
nnz(S::TensorStorage) = length(S)
SparseArrays.nnz(S::TensorStorage) = length(S)

offset(S::TensorStorage, block) = offset(blockoffsets(S), block)
12 changes: 7 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.7.5"
version = "0.7.6"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -20,6 +20,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SerializedElementArrays = "d3ce8812-9567-47e9-a7b5-65a6d70a3065"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Expand All @@ -46,14 +47,15 @@ DocStringExtensions = "0.9.3"
Functors = "0.2, 0.3, 0.4, 0.5"
HDF5 = "0.14, 0.15, 0.16, 0.17"
IsApprox = "0.1, 1, 2"
LinearAlgebra = "1.6"
LinearAlgebra = "1.10"
NDTensors = "0.3.34"
Pkg = "1.6"
Printf = "1.6"
Random = "1.6"
Pkg = "1.10"
Printf = "1.10"
Random = "1.10"
Requires = "1.1"
SerializedElementArrays = "0.1"
SimpleTraits = "0.9.4"
SparseArrays = "<0.0.1, 1.10"
StaticArrays = "0.12, 1.0"
Strided = "1.1, 2"
TimerOutputs = "0.5.5"
Expand Down
7 changes: 6 additions & 1 deletion src/itensor.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NDTensors: NDTensors, nnz
using .TagSets: TagSets, hastags, replacetags

# Private inner constructor
Expand Down Expand Up @@ -852,7 +853,11 @@ hasqns(T::Union{Tensor,ITensor}) = hasqns(inds(T))

eachnzblock(T::ITensor) = eachnzblock(tensor(T))

nnz(T::ITensor) = nnz(tensor(T))
# TODO: Switch this to `SparseArrays.nnz`, it is written
# this way for backwards compatibility since older versions
# of NDTensors had their own `NDTensors.nnz` function
# that didn't overload `SparseArrays.nnz`.
NDTensors.nnz(T::ITensor) = nnz(tensor(T))

nblocks(T::ITensor, args...) = nblocks(tensor(T), args...)

Expand Down

6 comments on commit 2e5da07

@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

@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
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/119399

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.65 -m "<description of version>" 2e5da0790e46b78ecb874fc35ec2257e8bc2ba12
git push origin NDTensors-v0.3.65

@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/119400

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 v0.7.6 -m "<description of version>" 2e5da0790e46b78ecb874fc35ec2257e8bc2ba12
git push origin v0.7.6

Also, note the warning: Version 0.7.6 skips over 0.7.4
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@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
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 updated: JuliaRegistries/General/119400

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 v0.7.6 -m "<description of version>" 2e5da0790e46b78ecb874fc35ec2257e8bc2ba12
git push origin v0.7.6

Please sign in to comment.