Skip to content

Commit

Permalink
Merge pull request #93 from maartenvd/master
Browse files Browse the repository at this point in the history
fix partial trace
  • Loading branch information
Jutho authored Oct 7, 2020
2 parents 1d7f64d + 8e9f4a4 commit 08b8165
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/functions/ncon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function ncon(tensors, network,
throw(ArgumentError("invalid NCON network: $network -> $output"))
end
end
(tensors,network) = resolve_traces(tensors,network);
tree = order === nothing ? ncontree(network) : indexordertree(network, order)

if sym !== nothing
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Returns an array containing only those elements that appear exactly once in itr,
and without any elements that appear more than once.
"""
function unique2(itr)
out = collect(itr)
out = reshape(collect(itr),length(itr))
i = 1
while i < length(out)
inext = _findnext(isequal(out[i]), out, i+1)
Expand Down
14 changes: 14 additions & 0 deletions src/indexnotation/ncon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ function nconindexcompletion(ex)
return ex
end
end


function resolve_traces(tensors,network)
transformed = map(zip(tensors,network)) do (A,IA)
IC = unique2(IA);
if length(IC) == length(IA)
(A,IA)
else
(tensortrace(copy(A),IA,IC),IC)
end
end

first.(transformed),last.(transformed)
end

0 comments on commit 08b8165

Please sign in to comment.