[PR #1873] [MERGED] fix(tensor): transpose test uses symmetric tensor that can't detect wrong axis swap #33426

Closed
opened 2026-07-13 12:03:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1873
Author: @Shashank-Tripathi-07
Created: 6/16/2026
Status: Merged
Merged: 6/16/2026
Merged by: @profvjreddi

Base: mainHead: fix/transpose-test-symmetric-tensor


📝 Commits (1)

  • 393b95e fix transpose test to use a non-symmetric tensor that can catch wrong axis swaps

📊 Changes

1 file changed (+13 additions, -4 deletions)

View changed files

📝 tinytorch/src/01_tensor/01_tensor.py (+13 -4)

📄 Description

What breaks

test_unit_shape_manipulation() tests transpose(0, 2) on a (2, 2, 2) tensor and only asserts the output shape:

tensor_3d = Tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])  # (2, 2, 2)
swapped = tensor_3d.transpose(0, 2)
assert swapped.shape == (2, 2, 2)  # ALWAYS TRUE regardless of which axes are swapped

Because all three dimensions are equal, every possible axis swap produces the same (2, 2, 2) shape. A broken transpose() that swaps the wrong pair of axes, or even returns the input unchanged, passes this test.

Fix

Use a non-symmetric (2, 3, 4) tensor where each dimension size is distinct. Now transpose(0, 2) must produce (4, 3, 2) -- which is only achievable by swapping exactly axis 0 and axis 2. Add a data-value check verifying that element [i, j, k] appears at [k, j, i] in the result.

Test plan

  • pytest tinytorch/tests/01_tensor/ passes
  • A transpose() implementation that swaps the wrong axes now fails this test

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1873 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 6/16/2026 **Status:** ✅ Merged **Merged:** 6/16/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `main` ← **Head:** `fix/transpose-test-symmetric-tensor` --- ### 📝 Commits (1) - [`393b95e`](https://github.com/harvard-edge/cs249r_book/commit/393b95e68e0561c663a6d799b91b2c27f6fafcaf) fix transpose test to use a non-symmetric tensor that can catch wrong axis swaps ### 📊 Changes **1 file changed** (+13 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `tinytorch/src/01_tensor/01_tensor.py` (+13 -4) </details> ### 📄 Description ## What breaks `test_unit_shape_manipulation()` tests `transpose(0, 2)` on a `(2, 2, 2)` tensor and only asserts the output shape: ```python tensor_3d = Tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) # (2, 2, 2) swapped = tensor_3d.transpose(0, 2) assert swapped.shape == (2, 2, 2) # ALWAYS TRUE regardless of which axes are swapped ``` Because all three dimensions are equal, every possible axis swap produces the same `(2, 2, 2)` shape. A broken `transpose()` that swaps the wrong pair of axes, or even returns the input unchanged, passes this test. ## Fix Use a non-symmetric `(2, 3, 4)` tensor where each dimension size is distinct. Now `transpose(0, 2)` must produce `(4, 3, 2)` -- which is only achievable by swapping exactly axis 0 and axis 2. Add a data-value check verifying that element `[i, j, k]` appears at `[k, j, i]` in the result. ## Test plan - [ ] `pytest tinytorch/tests/01_tensor/` passes - [ ] A `transpose()` implementation that swaps the wrong axes now fails this test --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-07-13 12:03:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#33426