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

Unnesting Nested Subscripts and Attributes #1299

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

alexnick83
Copy link
Contributor

This PR adds preprocessing functionality to the frontend that un-nests nested subscripts and attributes. Example:

Original code:

def test_1(A: npt.NDArray[np.int32],
           i0: npt.NDArray[np.int32],
           i1: npt.NDArray[np.int32],
           i2: npt.NDArray[np.int32],
           i3: npt.NDArray[np.int32],
           i4: npt.NDArray[np.int32]) -> npt.NDArray[np.int32]:
    
    B = np.zeros_like(A)

    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            for k in range(A.shape[2]):
                for l in range(A.shape[3]):
                    B[i, :max(i2[j], i3[j]) - min(i2[j], i3[j]), k, l] = A[i0[i1[i]], min(i2[j], i3[j]) : max(i2[j], i3[j]), k, i4[l]]

    return (A + B).sum(axis=0)

Un-nested code:

def test_1(A: npt.NDArray[np.int32], i0: npt.NDArray[np.int32], i1: npt.NDArray[np.int32], i2: npt.NDArray[np.int32], i3: npt.NDArray[np.int32], i4: npt.NDArray[np.int32]) -> npt.NDArray[np.int32]:
    B = np.zeros_like(A)
    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            for k in range(A.shape[2]):
                for l in range(A.shape[3]):
                    __var_0 = max(i2[j], i3[j]) - min(i2[j], i3[j])
                    __var_1 = i1[i]
                    __var_2 = i0[__var_1]
                    __var_3 = min(i2[j], i3[j])
                    __var_4 = max(i2[j], i3[j])
                    __var_5 = i4[l]
                    B[i, :__var_0, k, l] = A[__var_2, __var_3:__var_4, k, __var_5]
    __var_6 = A + B
    return __var_6.sum(axis=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant