Conversation
…ating a UniTensor and contracting it with a (diagonal) identity UniTensor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #749 +/- ##
=======================================
Coverage 35.25% 35.26%
=======================================
Files 215 215
Lines 33095 33095
Branches 13196 13196
=======================================
+ Hits 11669 11670 +1
Misses 19512 19512
+ Partials 1914 1913 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| cytnx::UniTensor I_UT = cytnx::UniTensor::eye(Ndiag, {}, true, Tn.dtype(), Tn.device()); | ||
| // similar to _trace_nd_gpu | ||
| UniTensor UTn = UniTensor(Tn, false, 2); | ||
| I_UT.set_labels({UTn._impl->_labels[0], UTn._impl->_labels[1]}); | ||
|
|
||
| out = Contract(I_UT, UTn).get_block_(); |
There was a problem hiding this comment.
Is this less efficient than the original implementation?
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 736a1666b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| UniTensor UTn = UniTensor(Tn, false, 2); | ||
| I_UT.set_labels({UTn._impl->_labels[0], UTn._impl->_labels[1]}); | ||
|
|
||
| out = Contract(I_UT, UTn).get_block_(); |
There was a problem hiding this comment.
Handle rectangular matrix trace on GPU
Tensor::Trace computes Ndiag = min(dim[axisA], dim[axisB]), so rectangular traces are expected to work, but this GPU path now contracts eye(Ndiag) against the full 2D tensor. For inputs like shape (m,n) with m != n, one contracted label has size Ndiag while the tensor bond still has size max(m,n), so Contract sees mismatched bond dimensions and raises instead of returning the diagonal sum (CPU still handles this case).
Useful? React with 👍 / 👎.
Currently, Tensor.Trace corresponds to creating a UniTensor and contracting it with a (diagonal) identity UniTensor;
removed Nomp argument in internal Trace functions;
This fixes #735