Skip to content

Commit 2e5da07

Browse files
authoredNov 14, 2024
[NDTensors] [ITensors] Overload SparseArrays.nnz (#1582)
* [NDTensors] [ITensors] Overload SparseArrays.nnz * [NDTensors] Bump to v0.3.65 * [ITensors] Bump to v0.7.6
1 parent 57994ff commit 2e5da07

File tree

11 files changed

+34
-14
lines changed

11 files changed

+34
-14
lines changed
 

Diff for: ‎NDTensors/Project.toml

+4-4
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 <mfishman@flatironinstitute.org>"]
4-
version = "0.3.64"
4+
version = "0.3.65"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -73,15 +73,15 @@ HDF5 = "0.14, 0.15, 0.16, 0.17"
7373
HalfIntegers = "1"
7474
InlineStrings = "1"
7575
JLArrays = "0.1, 0.2"
76-
LinearAlgebra = "<0.0.1, 1.6"
76+
LinearAlgebra = "<0.0.1, 1.10"
7777
MacroTools = "0.5"
7878
MappedArrays = "0.4"
7979
Metal = "1"
8080
Octavian = "0.3"
8181
PackageExtensionCompat = "1"
82-
Random = "<0.0.1, 1.6"
82+
Random = "<0.0.1, 1.10"
8383
SimpleTraits = "0.9.4"
84-
SparseArrays = "<0.0.1, 1.6"
84+
SparseArrays = "<0.0.1, 1.10"
8585
SplitApplyCombine = "1.2.2"
8686
StaticArrays = "0.12, 1.0"
8787
Strided = "2"

Diff for: ‎NDTensors/src/blocksparse/blockoffsets.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SparseArrays: SparseArrays
2+
13
#
24
# BlockOffsets
35
#
@@ -57,7 +59,7 @@ function offset(bofs::BlockOffsets{N}, block::Block{N}) where {N}
5759
return bofs[block]
5860
end
5961

60-
function nnz(bofs::BlockOffsets, inds)
62+
function SparseArrays.nnz(bofs::BlockOffsets, inds)
6163
_nnz = 0
6264
nnzblocks(bofs) == 0 && return _nnz
6365
for block in eachnzblock(bofs)

Diff for: ‎NDTensors/src/blocksparse/blocksparsetensor.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using SparseArrays: nnz
12
using .TypeParameterAccessors: similartype
23

34
#

Diff for: ‎NDTensors/src/blocksparse/similar.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using SparseArrays: nnz
12
using .TypeParameterAccessors: similartype
23

34
# NDTensors.similar

Diff for: ‎NDTensors/src/dense/densetensor.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SparseArrays: nnz
2+
13
#
24
# DenseTensor (Tensor using Dense storage)
35
#

Diff for: ‎NDTensors/src/dense/tensoralgebra/contract.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SparseArrays: nnz
2+
13
function contraction_output(tensor1::DenseTensor, tensor2::DenseTensor, indsR)
24
tensortypeR = contraction_output_type(typeof(tensor1), typeof(tensor2), indsR)
35
return NDTensors.similar(tensortypeR, indsR)

Diff for: ‎NDTensors/src/empty/empty.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using SparseArrays: SparseArrays
12
using .TypeParameterAccessors: TypeParameterAccessors, set_eltype, similartype
23

34
#
@@ -66,7 +67,7 @@ isempty(::EmptyStorage) = true
6667

6768
nnzblocks(::EmptyStorage) = 0
6869

69-
nnz(::EmptyStorage) = 0
70+
SparseArrays.nnz(::EmptyStorage) = 0
7071

7172
function conj(::AllowAlias, S::EmptyStorage)
7273
return S

Diff for: ‎NDTensors/src/tensor/tensor.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SparseArrays: SparseArrays, nnz
2+
13
"""
24
Tensor{StoreT,IndsT}
35
@@ -307,7 +309,7 @@ eachnzblock(T::Tensor) = eachnzblock(storage(T))
307309

308310
blockoffsets(T::Tensor) = blockoffsets(storage(T))
309311
nnzblocks(T::Tensor) = nnzblocks(storage(T))
310-
nnz(T::Tensor) = nnz(storage(T))
312+
SparseArrays.nnz(T::Tensor) = nnz(storage(T))
311313
nblocks(T::Tensor) = nblocks(inds(T))
312314
blockdims(T::Tensor, block) = blockdims(inds(T), block)
313315
blockdim(T::Tensor, block) = blockdim(inds(T), block)

Diff for: ‎NDTensors/src/tensorstorage/tensorstorage.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SparseArrays: SparseArrays
2+
13
abstract type TensorStorage{ElT} <: AbstractVector{ElT} end
24

35
data(S::TensorStorage) = S.data
@@ -98,6 +100,6 @@ nzblocks(T::TensorStorage) = nzblocks(blockoffsets(T))
98100
eachnzblock(T::TensorStorage) = eachnzblock(blockoffsets(T))
99101

100102
nnzblocks(S::TensorStorage) = length(blockoffsets(S))
101-
nnz(S::TensorStorage) = length(S)
103+
SparseArrays.nnz(S::TensorStorage) = length(S)
102104

103105
offset(S::TensorStorage, block) = offset(blockoffsets(S), block)

Diff for: ‎Project.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensors"
22
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
33
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>", "Miles Stoudenmire <mstoudenmire@flatironinstitute.org>"]
4-
version = "0.7.5"
4+
version = "0.7.6"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -20,6 +20,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2020
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2121
SerializedElementArrays = "d3ce8812-9567-47e9-a7b5-65a6d70a3065"
2222
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
23+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2324
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2425
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
2526
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
@@ -46,14 +47,15 @@ DocStringExtensions = "0.9.3"
4647
Functors = "0.2, 0.3, 0.4, 0.5"
4748
HDF5 = "0.14, 0.15, 0.16, 0.17"
4849
IsApprox = "0.1, 1, 2"
49-
LinearAlgebra = "1.6"
50+
LinearAlgebra = "1.10"
5051
NDTensors = "0.3.34"
51-
Pkg = "1.6"
52-
Printf = "1.6"
53-
Random = "1.6"
52+
Pkg = "1.10"
53+
Printf = "1.10"
54+
Random = "1.10"
5455
Requires = "1.1"
5556
SerializedElementArrays = "0.1"
5657
SimpleTraits = "0.9.4"
58+
SparseArrays = "<0.0.1, 1.10"
5759
StaticArrays = "0.12, 1.0"
5860
Strided = "1.1, 2"
5961
TimerOutputs = "0.5.5"

Diff for: ‎src/itensor.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NDTensors: NDTensors, nnz
12
using .TagSets: TagSets, hastags, replacetags
23

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

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

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

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

0 commit comments

Comments
 (0)