mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-15 21:28:33 -05:00
[PR #1873] [MERGED] fix(tensor): transpose test uses symmetric tensor that can't detect wrong axis swap #30973
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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:
main← Head:fix/transpose-test-symmetric-tensor📝 Commits (1)
393b95efix 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()teststranspose(0, 2)on a(2, 2, 2)tensor and only asserts the output shape:Because all three dimensions are equal, every possible axis swap produces the same
(2, 2, 2)shape. A brokentranspose()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. Nowtranspose(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/passestranspose()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.