Skip to content

Commit

Permalink
update identity contraction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed May 14, 2024
1 parent ce6091e commit 5c0d6ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions cotengra/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,18 @@ def _build_expression(
# 'contraction' is a no-op

def fn(*arrays, backend=None):
# this is surprisingly complicated 'to do nothing', since we
# have to respect potential backend conversion
x = arrays[0]
if backend is None:
return arrays[0]
return ar.do("array", arrays[0], like=backend)
# haven't requested a specific backend, just return
return x
elif backend == ar.infer_backend(x):
# requested backend is the same as the input, just return
return x
else:
# requested backend is different, convert
return ar.do("array", arrays[0], like=backend)

elif len(term) == len(output):
# 'contraction' is just a transposition
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
extras_require={
"recommended": [
"cotengrust",
"cotengrust>=0.1.3",
"cytoolz",
"kahypar",
"networkx",
Expand Down Expand Up @@ -76,6 +76,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
keywords="tensor network contraction graph hypergraph partition einsum",
)

0 comments on commit 5c0d6ab

Please sign in to comment.