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

reduce on odd dim to any size? #119

Open
futurisold opened this issue Jun 1, 2021 · 2 comments
Open

reduce on odd dim to any size? #119

futurisold opened this issue Jun 1, 2021 · 2 comments
Labels
question Further information is requested

Comments

@futurisold
Copy link

futurisold commented Jun 1, 2021

Suppose an image has the following shape: (3 561 600).

I couldn't find a way to make it (3 280 300); is there any?

Sorry for this dumb question, but I really like your work, and I want to integrate it as much as possible into my projects.

All the best!

@futurisold futurisold changed the title einops on odd dimension? reduce on odd dim to any size? Jun 1, 2021
@arogozhnikov
Copy link
Owner

Hi @leoentersthevoid,
There is no support for such cases.
If those are to appear, they should be separate functions or explicit flags, so no need to wait since you can implement something like:

def truncate_to_divisible(x, divisors):
    assert len(x.shape) == len(divisors)
    selection = tuple()
    for axis, axis_length in enumerate(x.shape):
        div = divisors[axis]
        if div == 1:
            selection += (slice(None, None))
        else:
            selection += (slice(None, axis_length // div * div))
    return x[selection]

and use it like this:

truncate_to_divisible(x, (1, 2, 2))

@futurisold
Copy link
Author

@arogozhnikov, I see.

Thanks for the reply!

@arogozhnikov arogozhnikov added the question Further information is requested label Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants