Skip to content

implemented Trace for GPU#749

Open
manuschneider wants to merge 1 commit intomasterfrom
trace
Open

implemented Trace for GPU#749
manuschneider wants to merge 1 commit intomasterfrom
trace

Conversation

@manuschneider
Copy link
Collaborator

@manuschneider manuschneider commented Mar 18, 2026

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

…ating a UniTensor and contracting it with a (diagonal) identity UniTensor
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.26%. Comparing base (4080739) to head (736a166).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/linalg/Trace.cpp 16.66% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@manuschneider manuschneider added the Pending check/approval Issue fixed, and need feedback label Mar 18, 2026
Comment on lines +17 to +22
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_();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this less efficient than the original implementation?

@ianmccul
Copy link
Collaborator

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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_();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Pending check/approval Issue fixed, and need feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing GPU implementation for Trace

3 participants