Skip to content

Commit cebdbee

Browse files
Jutho HaegemanJutho Haegeman
authored andcommitted
Merge branch 'master' of github.com:Jutho/TensorOperations.jl
2 parents 4542c68 + 08b8165 commit cebdbee

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/functions/ncon.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function ncon(tensors, network,
5252
throw(ArgumentError("invalid NCON network: $network -> $output"))
5353
end
5454
end
55+
(tensors,network) = resolve_traces(tensors,network);
5556
tree = order === nothing ? ncontree(network) : indexordertree(network, order)
5657

5758
if sym !== nothing

src/implementation/indices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Returns an array containing only those elements that appear exactly once in itr,
3434
and without any elements that appear more than once.
3535
"""
3636
function unique2(itr)
37-
out = collect(itr)
37+
out = reshape(collect(itr),length(itr))
3838
i = 1
3939
while i < length(out)
4040
inext = _findnext(isequal(out[i]), out, i+1)

src/indexnotation/ncon.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,17 @@ function nconindexcompletion(ex)
8181
return ex
8282
end
8383
end
84+
85+
86+
function resolve_traces(tensors,network)
87+
transformed = map(zip(tensors,network)) do (A,IA)
88+
IC = unique2(IA);
89+
if length(IC) == length(IA)
90+
(A,IA)
91+
else
92+
(tensortrace(copy(A),IA,IC),IC)
93+
end
94+
end
95+
96+
first.(transformed),last.(transformed)
97+
end

0 commit comments

Comments
 (0)