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

[TensorAlgebra] Matricized QR tensor decomposition #1266

Merged
merged 34 commits into from
Nov 17, 2023

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Nov 17, 2023

This defines a function for performing a matricized QR decomposition of a tensor.

The high level API is:

julia> using NDTensors.TensorAlgebra

julia> using LinearAlgebra

julia> a = randn(2, 2, 2, 2);

julia> q, r = qr(a, (:a, :b, :c, :d), (:a, :c), (:b, :d));

julia> q
2×2×4 Array{Float64, 3}:
[:, :, 1] =
 -0.320888   0.370723
 -0.306767  -0.815775

[:, :, 2] =
  0.47314   -0.653369
 -0.515355  -0.289234

[:, :, 3] =
 -0.369393  -0.595887
  0.616975  -0.357504

[:, :, 4] =
 -0.732611  -0.283888
 -0.509553   0.350778

julia> r
4×2×2 Array{Float64, 3}:
[:, :, 1] =
 2.9428  -0.54139
 0.0      2.80448
 0.0      0.0
 0.0      0.0

[:, :, 2] =
 -0.225018  -0.0430216
  1.07535    0.0289476
 -1.58676    0.550383
  0.0        0.0227928

julia> a′ = TensorAlgebra.contract((:a, :b, :c, :d), q, (:a, :c, :qr), r, (:qr, :b, :d));

julia> norm(a - a′)
1.21523787027731e-15

We can also provide a permutation-based API, for example qr(a, (1, 3), (2, 4)) which would be equivalent to the example above.

There is currently a bug in TensorAlgebra.contract which is marked with a broken test so some label combinations can't be properly checked with TensorAlgebra.contract, I'll investigate that in a future PR. But the main point here is to get started with the general code patterns involving matricize and unmatricize for performing matricized tensor decompositions, i.e. these patterns and a lot of code can be shared with SVD and other decompositions.

mtfishman and others added 30 commits November 10, 2023 12:21
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…m:ITensor/ITensors.jl into NDTensors_blocksparsearray_tensor_algebra
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3f1afb8) 85.44% compared to head (a8fd705) 54.80%.

❗ Current head a8fd705 differs from pull request most recent head f9d2e7b. Consider uploading reports for the commit f9d2e7b to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1266       +/-   ##
===========================================
- Coverage   85.44%   54.80%   -30.64%     
===========================================
  Files          89       88        -1     
  Lines        8402     8349       -53     
===========================================
- Hits         7179     4576     -2603     
- Misses       1223     3773     +2550     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtfishman mtfishman merged commit c47eb7c into main Nov 17, 2023
9 checks passed
@mtfishman mtfishman deleted the TensorAlgebra_qr_decomposition branch November 17, 2023 21:12
@mtfishman mtfishman restored the TensorAlgebra_qr_decomposition branch November 17, 2023 21:12
@mtfishman mtfishman deleted the TensorAlgebra_qr_decomposition branch November 17, 2023 22:05
@emstoudenmire
Copy link
Collaborator

Nice – the interface looks really intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants