Skip to content

Commit e82cebe

Browse files
authored
Upgrade to NamedDimsArrays.jl v0.14 (#106)
1 parent ccad131 commit e82cebe

6 files changed

Lines changed: 35 additions & 37 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorBase"
22
uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
33
authors = ["ITensor developers <support@itensor.org> and contributors"]
4-
version = "0.4.5"
4+
version = "0.5.0"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -13,7 +13,7 @@ TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
1313
[compat]
1414
Accessors = "0.1.39"
1515
ConstructionBase = "1.6.0"
16-
NamedDimsArrays = "0.13"
16+
NamedDimsArrays = "0.14"
1717
Random = "1.10"
1818
TensorAlgebra = "0.3, 0.4, 0.5, 0.6"
1919
julia = "1.10"

docs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ ITensorBase = {path = ".."}
99

1010
[compat]
1111
Documenter = "1"
12-
ITensorBase = "0.4"
12+
ITensorBase = "0.5"
1313
Literate = "2"
14-
NamedDimsArrays = "0.13"
14+
NamedDimsArrays = "0.14"

examples/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
77
ITensorBase = {path = ".."}
88

99
[compat]
10-
ITensorBase = "0.4"
10+
ITensorBase = "0.5"
1111
LinearAlgebra = "1.10"
12-
NamedDimsArrays = "0.13"
12+
NamedDimsArrays = "0.14"

src/abstractitensor.jl

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using NamedDimsArrays: NamedDimsArrays, AbstractNamedDimsArray, NamedDimsArray, denamed,
2-
dimnames, inds, mapinds
1+
using NamedDimsArrays: NamedDimsArrays, AbstractNamedDimsArray, LittleSet, NamedDimsArray,
2+
denamed, dimnames, inds, mapinds
33

44
abstract type AbstractITensor <: AbstractNamedDimsArray{Any, Any} end
55

@@ -8,21 +8,16 @@ NamedDimsArrays.nameddimsconstructor(::Type{<:IndexName}) = ITensor
88
Base.ndims(::Type{<:AbstractITensor}) = Any
99

1010
struct ITensor <: AbstractITensor
11-
parent::AbstractArray
12-
inds
13-
function ITensor(parent::AbstractArray, dims)
14-
# This checks the shapes of the inputs.
15-
inds = NamedDimsArrays.to_inds(parent, dims)
16-
return new(parent, inds)
11+
denamed::AbstractArray
12+
dimnames
13+
function ITensor(denamed::AbstractArray, dimnames)
14+
ndims(denamed) == length(dimnames) ||
15+
throw(ArgumentError("Number of named dims must match ndims."))
16+
all(dimname -> dimname isa IndexName, dimnames) ||
17+
throw(ArgumentError("All dimnames must be of type IndexName."))
18+
return new(denamed, dimnames)
1719
end
1820
end
19-
Base.parent(a::ITensor) = getfield(a, :parent)
20-
NamedDimsArrays.inds(a::ITensor) = getfield(a, :inds)
21-
NamedDimsArrays.denamed(a::ITensor) = parent(a)
22-
23-
function ITensor(parent::AbstractArray, i1::Index, i_rest::Index...)
24-
return ITensor(parent, (i1, i_rest...))
25-
end
26-
function ITensor(parent::AbstractArray)
27-
return ITensor(parent, ())
28-
end
21+
NamedDimsArrays.dimnames(a::ITensor) = LittleSet(a.dimnames)
22+
NamedDimsArrays.denamed(a::ITensor) = a.denamed
23+
Base.parent(a::ITensor) = denamed(a)

test/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ ITensorBase = {path = ".."}
1212

1313
[compat]
1414
Aqua = "0.8.9"
15-
ITensorBase = "0.4"
15+
ITensorBase = "0.5"
1616
LinearAlgebra = "1.10"
17-
NamedDimsArrays = "0.13"
17+
NamedDimsArrays = "0.14"
1818
SafeTestsets = "0.1"
1919
Suppressor = "0.2"
2020
Test = "1.10"

test/test_basics.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
7070
elt = Float64
7171
i, j = Index.((2, 2))
7272
x = randn(elt, 2, 2)
73-
for a in (ITensor(x, i, j), ITensor(x, (i, j)))
74-
@test denamed(a) == x
75-
@test plev(i) == 0
76-
@test plev(prime(i)) == 1
77-
@test length(tags(i)) == 0
78-
a′ = mapinds(prime, a)
79-
@test denamed(a′) == x
80-
@test issetequal(inds(a′), (prime(i), prime(j)))
81-
end
73+
a = x[i, j]
74+
@test denamed(a) == x
75+
@test plev(i) == 0
76+
@test plev(prime(i)) == 1
77+
@test length(tags(i)) == 0
78+
a′ = mapinds(prime, a)
79+
@test denamed(a′) == x
80+
@test issetequal(inds(a′), (prime(i), prime(j)))
8281

83-
@test_throws ErrorException ITensor(randn(elt, 2, 2), Index.((2, 3)))
84-
@test_throws ErrorException ITensor(randn(elt, 4), Index.((2, 2)))
82+
# For now, the `ITensor` constructor is strict and only accepts a collection of
83+
# `IndexName` as dimnames.
84+
@test_throws ArgumentError ITensor(randn(elt, 2, 2), Index.((2, 2)))
85+
@test_throws ArgumentError ITensor(randn(elt, 2, 2), Index.((2, 3)))
86+
@test_throws ArgumentError ITensor(randn(elt, 4), Index.((2, 2)))
87+
@test_throws MethodError ITensor(randn(elt, 2, 2), Index(2), Index(2))
8588

8689
i, j = Index.((3, 4))
8790
a = randn(elt, i, j)

0 commit comments

Comments
 (0)