Skip to content

Commit f49a064

Browse files
committed
Restore old ITensor() behaviour
1 parent c9bf435 commit f49a064

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/itensor.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ ITensor(is::Indices) = ITensor(Float64, is)
235235
ITensor(inds::Index...) = ITensor(Float64, IndexSet(inds...))
236236

237237
# To fix ambiguity with QN Index version
238-
ITensor() = emptyITensor()
238+
ITensor() = ITensor(Float64, IndexSet())
239239

240240
"""
241241
ITensor([::Type{ElT} = Float64, ]::UndefInitializer, inds)
@@ -1230,25 +1230,13 @@ end
12301230
-(A::ITensor) = itensor(-tensor(A))
12311231

12321232
function (A::ITensor + B::ITensor)
1233-
if ndims(A) == 0 && ndims(B) > 0 && store(A) isa NDTensors.Empty
1234-
return copy(B)
1235-
end
1236-
if ndims(B) == 0 && ndims(A) > 0 && store(B) isa NDTensors.Empty
1237-
return copy(A)
1238-
end
12391233
ndims(A) != ndims(B) && throw(DimensionMismatch("cannot add ITensors with different numbers of indices"))
12401234
C = copy(A)
12411235
C .+= B
12421236
return C
12431237
end
12441238

12451239
function (A::ITensor - B::ITensor)
1246-
if ndims(A) == 0 && ndims(B) > 0 && store(A) isa NDTensors.Empty
1247-
return -copy(B)
1248-
end
1249-
if ndims(B) == 0 && ndims(A) > 0 && store(B) isa NDTensors.Empty
1250-
return copy(A)
1251-
end
12521240
ndims(A) != ndims(B) && throw(DimensionMismatch("cannot subtract ITensors with different numbers of indices"))
12531241
C = copy(A)
12541242
C .-= B

test/itensor.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ digits(::Type{T},x...) where {T} = T(sum([x[length(x)-k+1]*10^(k-1) for k=1:leng
2020

2121
@testset "Default" begin
2222
A = ITensor()
23-
@test store(A) isa NDTensors.Empty{Float64}
23+
@test store(A) isa NDTensors.Dense{Float64}
2424
end
2525

2626
@testset "Undef with index" begin
@@ -501,23 +501,24 @@ end
501501
a = [1.0; 2.0]
502502
A = itensor(a,i)
503503
B = ITensor()
504-
@test A + B == A
504+
@test_throws DimensionMismatch A + B
505+
a = [1.0; 2.0]
505506
a = [1.0; 2.0]
506507
A = itensor(a,i)
507508
B = ITensor(2.0)
508509
@test_throws DimensionMismatch A - B
509510
a = [1.0; 2.0]
510511
A = itensor(a,i)
511512
B = ITensor()
512-
@test A - B == A
513+
@test_throws DimensionMismatch A - B
513514
a = [1.0; 2.0]
514515
A = itensor(a,i)
515516
B = ITensor(2.0)
516517
@test_throws DimensionMismatch B - A
517518
a = [1.0; 2.0]
518519
A = itensor(a,i)
519520
B = ITensor()
520-
@test B - A == -A
521+
@test_throws DimensionMismatch B - A
521522
a = [1.0; 2.0]
522523
b = [3.0; 4.0]
523524
A = itensor(a,i)

0 commit comments

Comments
 (0)