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

Indexing issue #918

Open
serge-sans-paille opened this issue May 24, 2018 · 2 comments
Open

Indexing issue #918

serge-sans-paille opened this issue May 24, 2018 · 2 comments

Comments

@serge-sans-paille
Copy link
Owner

The following code does not compile

#pythran export get(int[:,:], int, int, int, int, str)
#pythran export get(int[:,:], int, int, int, int)
import numpy as np
def get(img, y0, y1, x0, x1, mode="reflect"):
    #xs, ys = np.mgrid[y0:y1, x0:x1]
    xs = np.ones((y1-y0, x1-x0))
    ys = np.ones((y1-y0, x1-x0))
    height, width = img.shape

    if mode == "nearest":
        xs = np.clip(xs, 0, height-1)
        ys = np.clip(ys, 0, width-1)

    elif mode == "wrap":
        xs = xs % height
        ys = ys % width

    elif mode == "reflect":
        maxh = height-1
        maxw = width-1

        # An unobvious way of performing reflecting modulo
        # You should comment this
        xs = np.absolute((xs + maxh) % (2 * maxh) - maxh)
        ys = np.absolute((ys + maxw) % (2 * maxw) - maxw)

    elif mode == "constant":
        output = np.empty((y1-y0, x1-x0))
        output.fill(0) # WHAT THE CONSTANT IS

        # LOADS of bounds checks and restrictions
        # You should comment this
        target_section = output[max(0, -y0):min(y1-y0, -y0+height), max(0, -x0):min(x1-x0, -x0+width)]
        new_fill = img[max(0, y0):min(height, y1), max(0, x0):min(width, x1)]

        # Crop both the sections, so that they're both the size of the smallest
        # Use more lines; I'm too lazy right now
        target_section[:new_fill.shape[0], :new_fill.shape[1]] = new_fill[:target_section.shape[0], :target_section.shape[1]]

        return output

    else:
        raise NotImplementedError("Unknown mode")

    return img[xs, ys]

but why? Related to https://linuxfr.org/nodes/114545/comments/1739776

@serge-sans-paille
Copy link
Owner Author

Ok, the problem comes from the imgs[cs,ys] notation which is not supported yet.

@serge-sans-paille
Copy link
Owner Author

And again, it's related to #926

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

No branches or pull requests

1 participant