Skip to content

Commit b1794f7

Browse files
committed
Check shapes in ITensor constructor
1 parent 1c2c870 commit b1794f7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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 <[email protected]> and contributors"]
4-
version = "0.1.15"
4+
version = "0.1.16"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -32,7 +32,7 @@ FillArrays = "1.13.0"
3232
GradedUnitRanges = "0.1.4"
3333
LinearAlgebra = "1.10"
3434
MapBroadcast = "0.1.5"
35-
NamedDimsArrays = "0.4"
35+
NamedDimsArrays = "0.4.5"
3636
SparseArraysBase = "0.2.11"
3737
UnallocatedArrays = "0.1.1"
3838
UnspecifiedTypes = "0.1.1"

src/abstractitensor.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ end
8080
mutable struct ITensor <: AbstractITensor
8181
parent::AbstractArray
8282
nameddimsindices
83+
function ITensor(parent::AbstractArray, dims)
84+
# This checks the shapes of the inputs.
85+
nameddimsindices = NamedDimsArrays.to_nameddimsindices(parent, dims)
86+
return new(parent, nameddimsindices)
87+
end
8388
end
8489
Base.parent(a::ITensor) = a.parent
8590
NamedDimsArrays.nameddimsindices(a::ITensor) = a.nameddimsindices

test/test_basics.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ using ITensorBase:
1818
using NamedDimsArrays: dename, name, named
1919
using SparseArraysBase: oneelement
2020
using SymmetrySectors: U1
21-
using Test: @test, @test_broken, @testset
21+
using Test: @test, @test_broken, @test_throws, @testset
2222

2323
@testset "ITensorBase" begin
2424
@testset "Basics" begin
25+
elt = Float64
2526
i, j = Index.((2, 2))
26-
x = randn(2, 2)
27+
x = randn(elt, 2, 2)
2728
for a in (ITensor(x, i, j), ITensor(x, (i, j)))
2829
@test dename(a) == x
2930
@test plev(i) == 0
@@ -34,6 +35,9 @@ using Test: @test, @test_broken, @testset
3435
@test issetequal(inds(a′), (prime(i), prime(j)))
3536
end
3637

38+
@test_throws ErrorException ITensor(randn(elt, 2, 2), Index.((2, 3)))
39+
@test_throws ErrorException ITensor(randn(elt, 4), Index.((2, 2)))
40+
3741
i = Index(2)
3842
i = settag(i, "X", "x")
3943
@test hastag(i, "X")

0 commit comments

Comments
 (0)