Skip to content

Check blockidx out of range for dense UniTensor#701

Open
manuschneider wants to merge 3 commits intomasterfrom
fix_dense_blockidx_out_of_range
Open

Check blockidx out of range for dense UniTensor#701
manuschneider wants to merge 3 commits intomasterfrom
fix_dense_blockidx_out_of_range

Conversation

@manuschneider
Copy link
Collaborator

Fixes #176 and #298

… any argument to avoid overhead of argument check; did not do this for put_block(_) for code readability
@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 48.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.47%. Comparing base (19643a1) to head (1c9a03f).
⚠️ Report is 112 commits behind head on master.

Files with missing lines Patch % Lines
include/UniTensor.hpp 48.00% 9 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #701      +/-   ##
==========================================
+ Coverage   32.74%   35.47%   +2.72%     
==========================================
  Files         215      215              
  Lines       35065    33089    -1976     
  Branches    14070    13175     -895     
==========================================
+ Hits        11482    11737     +255     
+ Misses      21708    19428    -2280     
- Partials     1875     1924      +49     

☔ 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 this to the v1.1.0 milestone Dec 11, 2025
@manuschneider manuschneider added the Pending check/approval Issue fixed, and need feedback label Feb 11, 2026
@ianmccul
Copy link
Collaborator

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Bravo.

ℹ️ 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".

Copy link
Collaborator

@pcchen pcchen left a comment

Choose a reason for hiding this comment

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

Posted by Claude Code on behalf of @pcchen

Overall: The fix is correct in spirit and the tests are properly un-gated. There is one critical bug and a couple of minor issues.


Critical Bug — Wrong method name in put_block_ error message

In put_block_, the new error message reads:

"invalid. Use get_block_(0).\n"

But it is inside put_block_, so it should say "invalid. Use put_block_(0).\n". This is a copy-paste error from the get_block_ implementation.


Minor — %d format specifier for cytnx_uint64

All four new cytnx_error_msg calls use %d to print a cytnx_uint64 value. Since cytnx_uint64 is an unsigned 64-bit integer, this is technically undefined behavior — %lu or %llu should be used. (This may be a pre-existing codebase-wide pattern, but worth fixing here since you're touching it.)


Minor — API inconsistency between get_block and put_block

get_block/get_block_ are split into two overloads (no-arg fast path + arg-with-check), but put_block/put_block_ remain a single function with the check inline. The commit message explains this was intentional ("for code readability"), but it creates an inconsistent API. Users looking at the put_block signature will still see idx = 0 as a default and may not expect an error. Consider applying the same two-overload pattern for consistency.


Positive

  • Core logic (idx != 0 guard) is correct for all four methods.
  • cytnx_error_msg throws std::logic_error (confirmed in cytnx_error.hpp:46), so the tests' EXPECT_THROW(..., std::logic_error) will pass.
  • Removing the #if FAIL_CASE_OPEN guards properly enables the previously-skipped tests.
  • Typo fix "convinent" → "convenient" is good.

…ifier

- Fix copy-paste bug: put_block_ error message incorrectly said "Use
  get_block_(0)" instead of "Use put_block_(0)"
- Replace %d with %llu (and cast to unsigned long long) for cytnx_uint64
  in all four new error messages (get_block, get_block_ x2, put_block,
  put_block_) to avoid undefined behavior
- Apply the same two-overload pattern used by get_block/get_block_ to
  put_block/put_block_: no-arg fast path + idx-with-check overload that
  delegates to it, making the API consistent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

get_block(blockindex) should drop an error if blockindex != 0 for non-symmetric tensors

3 participants