|
1 | 1 | using DiagonalArrays: δ, delta, diagview |
2 | | -using ITensorBase: |
3 | | - ITensorBase, |
4 | | - ITensor, |
5 | | - Index, |
6 | | - gettag, |
7 | | - hastag, |
8 | | - plev, |
9 | | - prime, |
10 | | - setplev, |
11 | | - settag, |
12 | | - tags, |
13 | | - unsettag |
| 2 | +using ITensorBase: ITensorBase, ITensor, Index, IndexName, gettag, hastag, plev, prime, |
| 3 | + setplev, settag, tags, unsettag |
14 | 4 | using NamedDimsArrays: dename, inds, mapinds, name, named |
15 | 5 | using SparseArraysBase: oneelement |
16 | 6 | using LinearAlgebra: factorize |
17 | 7 | using Test: @test, @test_broken, @test_throws, @testset |
18 | 8 |
|
19 | 9 | const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) |
20 | 10 | @testset "ITensorBase" begin |
21 | | - @testset "Basics" begin |
| 11 | + @testset "IndexName" begin |
| 12 | + n1 = IndexName(; id = UInt64(0)) |
| 13 | + n2 = IndexName(; id = UInt64(0)) |
| 14 | + @test n1 == n2 |
| 15 | + @test isequal(n1, n2) |
| 16 | + @test hash(n1) ≡ hash(n2) |
| 17 | + |
| 18 | + n1 = IndexName(; id = UInt64(0)) |
| 19 | + n2 = IndexName(; id = UInt64(1)) |
| 20 | + @test n1 ≠ n2 |
| 21 | + @test !isequal(n1, n2) |
| 22 | + @test n1 < n2 |
| 23 | + @test isless(n1, n2) |
| 24 | + @test hash(n1) ≠ hash(n2) |
| 25 | + |
| 26 | + n1 = IndexName(; id = UInt64(0), plev = 0) |
| 27 | + n2 = IndexName(; id = UInt64(0), plev = 1) |
| 28 | + @test n1 ≠ n2 |
| 29 | + @test !isequal(n1, n2) |
| 30 | + @test n1 < n2 |
| 31 | + @test isless(n1, n2) |
| 32 | + @test hash(n1) ≠ hash(n2) |
| 33 | + end |
| 34 | + @testset "Index basics" begin |
| 35 | + i = Index(2) |
| 36 | + @test plev(i) == 0 |
| 37 | + i = setplev(i, 2) |
| 38 | + @test plev(i) == 2 |
| 39 | + |
| 40 | + i = Index(2) |
| 41 | + i = settag(i, "X", "x") |
| 42 | + @test hastag(i, "X") |
| 43 | + @test !hastag(i, "Y") |
| 44 | + @test gettag(i, "X") == "x" |
| 45 | + i = unsettag(i, "X") |
| 46 | + @test isnothing(gettag(i, "X", nothing)) |
| 47 | + @test !hastag(i, "X") |
| 48 | + @test !hastag(i, "Y") |
| 49 | + |
| 50 | + i = Index(Base.OneTo(2)) |
| 51 | + @test length(i) == named(2, name(i)) |
| 52 | + @test dename(length(i)) == 2 |
| 53 | + @test dename(i) == 1:2 |
| 54 | + @test plev(i) == 0 |
| 55 | + @test length(tags(i)) == 0 |
| 56 | + |
| 57 | + for i in ( |
| 58 | + Index(2; tags = Dict(["X" => "Y"])), |
| 59 | + Index(2; tags = ["X" => "Y"]), |
| 60 | + Index(2; tags = ("X" => "Y",)), |
| 61 | + Index(2; tags = "X" => "Y"), |
| 62 | + ) |
| 63 | + @test Int(length(i)) == 2 |
| 64 | + @test hastag(i, "X") |
| 65 | + @test gettag(i, "X") == "Y" |
| 66 | + @test plev(i) == 0 |
| 67 | + @test length(tags(i)) == 1 |
| 68 | + end |
| 69 | + |
| 70 | + end |
| 71 | + @testset "ITensor basics" begin |
22 | 72 | elt = Float64 |
23 | 73 | i, j = Index.((2, 2)) |
24 | 74 | x = randn(elt, 2, 2) |
@@ -57,41 +107,6 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) |
57 | 107 | @test a == b |
58 | 108 | @test dename(a) == dename(b, (i, j, k)) |
59 | 109 | @test dename(a) == permutedims(dename(b), (2, 3, 1)) |
60 | | - |
61 | | - i = Index(2) |
62 | | - @test plev(i) == 0 |
63 | | - i = setplev(i, 2) |
64 | | - @test plev(i) == 2 |
65 | | - |
66 | | - i = Index(2) |
67 | | - i = settag(i, "X", "x") |
68 | | - @test hastag(i, "X") |
69 | | - @test !hastag(i, "Y") |
70 | | - @test gettag(i, "X") == "x" |
71 | | - i = unsettag(i, "X") |
72 | | - @test isnothing(gettag(i, "X", nothing)) |
73 | | - @test !hastag(i, "X") |
74 | | - @test !hastag(i, "Y") |
75 | | - |
76 | | - i = Index(Base.OneTo(2)) |
77 | | - @test length(i) == named(2, name(i)) |
78 | | - @test dename(length(i)) == 2 |
79 | | - @test dename(i) == 1:2 |
80 | | - @test plev(i) == 0 |
81 | | - @test length(tags(i)) == 0 |
82 | | - |
83 | | - for i in ( |
84 | | - Index(2; tags = Dict(["X" => "Y"])), |
85 | | - Index(2; tags = ["X" => "Y"]), |
86 | | - Index(2; tags = ("X" => "Y",)), |
87 | | - Index(2; tags = "X" => "Y"), |
88 | | - ) |
89 | | - @test Int(length(i)) == 2 |
90 | | - @test hastag(i, "X") |
91 | | - @test gettag(i, "X") == "Y" |
92 | | - @test plev(i) == 0 |
93 | | - @test length(tags(i)) == 1 |
94 | | - end |
95 | 110 | end |
96 | 111 | @testset "show" begin |
97 | 112 | id = rand(UInt64) |
|
0 commit comments