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
Feature request: support out argument in reshape #7488
Comments
It sounds like your use cases would be better served by a |
Or maybe |
I do have an appropriately-sized array. It is potentially very large (4+ GiB) and is based on shared-memory instead of the standard memory backing, so a regular copy would not be helpful, just as will other memory backings, like memmapped files. So, for my needs, a |
Its orthogonal, but as a workaround you can reshape the out array instead of the input array:
of course that gives a little restriction on the out arrays strides maybe, but in practice you probably don't care about that. |
For the mean time I am doing something similar to that, but catching the |
The copyto code does not do two copies, it just does one copy? |
My complete solution for the moment is as follows:
Remember, it is An alternative to having an |
@coderforlife yes right. I read it the other way around, like you have in your complete solution there, where you try to reshape the out array to the old arrays shape, which should usually work. One thing is that even for your hack, a The Since, it is crazy, this pure python function might be almost as fast as the successful try block and probably a lot faster then that flat assignment:
|
Actually I realized there is a CopyAsFlat or so in the C-api as well (not sure whether exposed, or fast, or...). I guess these are all real options that could be nice if anyone actually does them. |
Sorry for the delay, I finally got around to doing some testing. My current version of Numpy doesn't have Also, back when I originally did this, I tried to make an In any case, for some examples I get the following timings:
I will try to version to see if |
The
out
argument would be used for the output copy. This means that the array will always be copied, even if it could be reshaped without copying, thus becoming the opposite of doinga.shape = (...)
which never copies. This would allow one to copy the data where both the array being reshaped and the destination array cannot be reshaped to the other without a copy being made and not make an intermediate. This would also give options for emulatingrepeat
andtile
with anout
argument by usingas_strided
andreshape
.The text was updated successfully, but these errors were encountered: