Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Jutho/TensorOperations.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho Haegeman authored and Jutho Haegeman committed Oct 8, 2020
2 parents 4542c68 + 08b8165 commit cebdbee
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

2 comments on commit cebdbee

@Jutho
Copy link
Owner

@Jutho Jutho commented on cebdbee Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/22574

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.0.1 -m "<description of version>" cebdbee51bb87b142c9fbf39864358854f75b8b9
git push origin v3.0.1

Please sign in to comment.