One function

coordinates in NVlabs/CuTe

The author described this change as fix: add required return statements to `coordinates` function (#1). It counts as a record because the check below fails on the code as it stood at f46131c73 and passes on 891d8757d, with nothing else changed between the two runs.

Fix saved2026-08-17
Sharing licenceApache-2.0 · LICENSE.txt
Change size+3 0

What the code was meant to do, written into the code itself as a docstring

Generate all natural coordinates of `shape`, in *colexicographical* order. Post-conditions: list(coordinates(s)) == [idx2crd(i, s) for i in range(size(s))] [crd2idx(c, s) for c in coordinates(s)] == list(range(size(s))) Examples: list(coordinates(6)) == [0, 1, 2, 3, 4, 5] list(coordinates((3, 2))) == [(0,0), (1,0), (2,0), (0,1), (1,1), (2,1)] list(coordinates((2, (2, 2)))) == [(0,(0,0)), (1,(0,0)), (0,(1,0)), (1,(1,0)), (0,(0,1)), (1,(0,1)), (0,(1,1)), (1,(1,1))]

The change

1414 """
1515 if is_int(shape):
1616 yield from range(shape)
17+ return
1718 if is_tuple(shape):
1819 if len(shape) == 0:
1920 yield ()
21+ return
2022 for rest in coordinates(shape[1:]):
2123 for c in coordinates(shape[0]):
2224 yield (c,) + rest
25+ return
2326 raise TypeError(f"coordinates({shape})")

The check that tells the two apart

failpass·test/test_htuple.py::TestHTuple::test_coordinates

Check file test/test_htuple.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf46131c7346292b4202a40a6759d6801125f11ff
Broken version dated2026-08-17
Modulepycute.shape
Units changedcoordinates
Fingerprint38b8457556fd740a
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.