Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions quimb/tensor/decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ def _trim_and_renorm_svd_result(
return U, None, VH


@compose
def identity(x, backend=None, **kwargs):
"""
No-op "decomposition" that leaves the input unchanged. Can be useful to quickly build a tensor network representing a given tensor "as is".
"""

with backend_like(backend):
if x.shape[0] < x.shape[1]:
return do("eye", x.shape[0]), do("ones", x.shape[0]), x
else:
return x, do("ones", x.shape[1]), do("eye", x.shape[1])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The middle element should probably just be left as None, otherwise it flags to calling functions above that 'singular values' have been returned. This happens with other methods only when the option absorb=None. Or one could add that option and but default to absorb=0 (which means absorbed on either side), if you imagine that it might be useful to initialize simple update gauges for example.

I also suggest here using do("eye", x.shape[0], like=x) and do("ones", x.shape[0], like=x) rather than backend_like since autoray now supports picking up the correct device and dtype for these array creation routines.



@compose
def svd_truncated(
x,
Expand Down
1 change: 1 addition & 0 deletions quimb/tensor/tensor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def rand_uuid(base=""):

_VALID_SPLIT_GET = {None, "arrays", "tensors", "values"}
_SPLIT_FNS = {
"identity": decomp.identity,
"svd": decomp.svd_truncated,
"eig": decomp.svd_via_eig_truncated,
"lu": decomp.lu_truncated,
Expand Down