Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an 'identity' tensor splitting option #241

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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 @@
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

Check warning on line 196 in quimb/tensor/decomp.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/decomp.py#L194-L196

Added lines #L194 - L196 were not covered by tests
else:
return x, do("ones", x.shape[1]), do("eye", x.shape[1])

Check warning on line 198 in quimb/tensor/decomp.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/decomp.py#L198

Added line #L198 was not covered by tests
Copy link
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
Loading