Skip to content

Refactor print to support arbitrary tensor dimensions#1193

Open
tmartin-gh wants to merge 2 commits into
NVIDIA:mainfrom
tmartin-gh:tm/print_refactor
Open

Refactor print to support arbitrary tensor dimensions#1193
tmartin-gh wants to merge 2 commits into
NVIDIA:mainfrom
tmartin-gh:tm/print_refactor

Conversation

@tmartin-gh
Copy link
Copy Markdown
Collaborator

No description provided.

@tmartin-gh tmartin-gh requested a review from cliffburdick May 27, 2026 22:57
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 27, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR replaces the hard-coded rank-3 and rank-4 print loops in InternalPrint with three generic recursive template helpers (PrintDefaultSlices, PrintMlabCat, PrintPythonRecursive) and removes the MATX_STATIC_ASSERT(Op::Rank() <= 4, …) gate, so all three print formats now work for any tensor rank ≥ 3.

  • include/matx/core/print.h: Adds PrintIndexArray, GetPrintExtents, and three format-specific recursive helpers; the else branch in InternalPrint dispatches to them for rank ≥ 3 while leaving the dedicated 0-D, 1-D, and 2-D paths untouched.
  • test/00_io/PrintTests.cu: Adds DefaultTest5D, MlabTest5D, and PythonTest5D with exact string comparisons, verifying all three format paths for a rank-5 tensor.
  • test/00_operators/print_test.cu / examples/print_styles.cu: Smoke-test and example usage extended to a 5-D tensor in all three formats.

Confidence Score: 5/5

Safe to merge — the refactor is self-contained to the print subsystem, all three format paths are verified by exact-string tests for the new 5-D case, and the 3-D/4-D test suite continues to validate backward-compatible output.

The generic recursive helpers produce output that is character-for-character identical to the removed hand-rolled loops for ranks 3 and 4, as confirmed by the existing exact-match tests. The new helpers extend cleanly to rank 5+, covered by three new exact-output tests. No incorrect indexing, off-by-one, or dangling-reference issues were found during detailed tracing of the template recursion and indentation logic.

No files require special attention.

Important Files Changed

Filename Overview
include/matx/core/print.h Core refactor: removes rank <= 4 ceiling, replaces hand-rolled 3D/4D loops with generic recursive helpers (PrintDefaultSlices, PrintMlabCat, PrintPythonRecursive) that work for any rank >= 3.
test/00_io/PrintTests.cu Adds DefaultTest5D, MlabTest5D, and PythonTest5D tests with exact string comparisons for a reshaped {2,2,1,2,2} tensor, exercising all three format paths of the new generic helpers.
test/00_operators/print_test.cu Smoke-tests a 5D tensor with all three format types using non-zero dim bounds; no output assertion but verifies no crash/compile failure for rank > 4.
examples/print_styles.cu Adds a 5D reshape A5 and prints it in all three formats to demonstrate the new capability; straightforward example extension.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["InternalPrint"] --> B{sizeof Args}
    B -->|0| C["PrintVal scalar"]
    B -->|1| D["1-D loop"]
    B -->|2| E["2-D loop"]
    B -->|3+| F["GetPrintExtents"]
    F --> G{PRINT_FORMAT_TYPE}
    G -->|DEFAULT| H["PrintDefaultSlices"]
    G -->|MLAB| I["PrintMlabCat"]
    G -->|PYTHON| J["PrintPythonRecursive"]
Loading

Reviews (2): Last reviewed commit: "Add MlabTest5D and PythonTest5D PrintTes..." | Re-trigger Greptile

Comment thread test/00_io/PrintTests.cu
@tmartin-gh
Copy link
Copy Markdown
Collaborator Author

/build

@tmartin-gh tmartin-gh self-assigned this May 28, 2026
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage is 93.593%tmartin-gh:tm/print_refactor into NVIDIA:main. No base build found for NVIDIA:main.

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