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.53% 35.53%
=======================================
Files 214 214
Lines 33016 33018 +2
Branches 13133 13133
=======================================
+ Hits 11731 11732 +1
- Misses 19361 19362 +1
Partials 1924 1924 ☔ 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 👍 / 👎.
…nt number of elements is currently not implemented
|
I do not think that tracing over indices with different dimensions is an essential feature that we need to support at the moment. In the long term, it would be good to implement more efficient ways to calculate the trace on both CPU and GPU without multiplying by the identity. Then, we can also decide whether to allow traces over indices of different lengths. This is not a high priority currently, though. |
|
I think there is no reason to ever allow trace over a non-square tensor. By definition that means that the left right indices represent different spaces, so the trace is meaningless. In the special case where one space is a diagonal projection |
|
An error message is now thrown in all cases where the index dimensions of the traced indices do not match. |
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