[Fix] fix make_coord to require tuple arg and add crd2idx tests#251
Open
jli-melchior wants to merge 2 commits intomainfrom
Open
[Fix] fix make_coord to require tuple arg and add crd2idx tests#251jli-melchior wants to merge 2 commits intomainfrom
jli-melchior wants to merge 2 commits intomainfrom
Conversation
Change make_coord(*coord) to make_coord(coord) so that passing multiple args like make_coord(r, c) raises a clear TypeError instead of silently creating a wrong-rank coordinate. Update the one caller in kernels/layout_utils.py and add comprehensive pytest-compatible tests covering col-major, row-major, 1D, 3D layouts and error cases.
sjfeng1999
reviewed
Mar 20, 2026
python/flydsl/expr/primitive.py
Outdated
|
|
||
| @traced_op | ||
| def make_coord(*coord, loc=None, ip=None): | ||
| def make_coord(coord, loc=None, ip=None): |
Contributor
There was a problem hiding this comment.
make_coord doesn't only accept a tuple. It is the same as make_shape and make_stride. There is no need to change.
Contributor
Author
There was a problem hiding this comment.
so we can let make_coord not only accept a tuple, but also a variable-length arguments?
Revert make_coord to *args signature (consistent with make_shape and make_stride), but auto-unwrap a single tuple argument so both make_coord(r, c) and make_coord((r, c)) produce the same result. Update tests to verify both calling conventions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #224
make_coord((r, c))(passing a tuple) causes a C++ assertion failure (coord.rank() == shape.rank()) inlayoutCrd2IdxTTTbecause*argswraps the tuple into((r, c),)— a rank-1 nested IntTuple instead of a flat rank-2 one. Users following thelayout_system_guide.mddocumentation hit this crash with no helpful error message.Technical Details
python/flydsl/expr/primitive.py: Keepmake_coord(*coord)varargs signature (consistent withmake_shapeandmake_stride), but auto-unwrap when a single tuple argument is passed. This makes both calling conventions work identically:make_coord(r, c)— varargs form (original)make_coord((r, c))— tuple form (now also supported)tests/unit/Layout/test_crd2idx.py: Add 6 pytest-compatible tests:test_crd2idx_col_major_tuple— verifiesmake_coord((r, c))tuple formtest_crd2idx_col_major_varargs— verifiesmake_coord(r, c)varargs formtest_crd2idx_col_major_both_forms_equal— verifies both forms produce identical resultstest_crd2idx_row_major— row-major (4,8) layouttest_crd2idx_1d— 1D layouttest_crd2idx_3d— 3D layoutTest Plan
Test Result
Submission Checklist
make_coord(r, c)still works,make_coord((r, c))now also worksmake_shapeandmake_strideAPI design