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 all commits
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
12 changes: 12 additions & 0 deletions quimb/tensor/decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@
return U, None, VH


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

if x.shape[0] < x.shape[1]:
return do("eye", x.shape[0], like=x), None, x

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

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/decomp.py#L194-L195

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

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

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/decomp.py#L197

Added line #L197 was not covered by tests


@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