Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CuTe and PyCuTe idx2crd Behaviors The Same #1891

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion python/pycute/int_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,25 @@ def prefix_product(a, init=1):
return init


def idx2crd(idx, shape, stride=None):
def idx2crd(idx, shape):

if is_tuple(idx):
if is_tuple(shape): # tuple tuple tuple
assert len(idx) == len(shape)
return tuple(idx2crd(i, s) for i, s in zip(idx,shape))
else: # tuple "int" "int"
assert False # Error
else:
if is_tuple(shape): # "int" tuple tuple
tuple_idx = []
for i in range(len(shape)):
tuple_idx.append(idx2crd(idx // product(shape[:i]), shape[i]))
return tuple(tuple_idx)
else: # "int" "int" "int"
return idx % shape


def idx2crd(idx, shape, stride):
if stride is None:
stride = prefix_product(shape)

Expand Down