-
Notifications
You must be signed in to change notification settings - Fork 308
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
Fastest way to convert to vec/iterate elements #1339
Comments
By "indexed", do you mean "not the complete array, just a portion of it"? In general, |
Sorry, I meant a sliced array. E.g. the cropped image array from my "benchmark" was created in python like this:
Could you please explain this in more detail? Changing my above code to: let flat: Vec<f32> = ndarray.to_owned().to_vec().unwrap(); Gives me a So I tried using the let flat: Vec<f32> = ndarray
.as_array()
.to_owned()
.into_shape(ndarray.shape().iter().product::<usize>())
.unwrap()
.to_vec(); This clocked in at 1.1sec, which is still 6x slower than |
I did some further testing and the main reason So I also found the |
If you do assume a dimensionality of 3, you could also change your Python API to expect |
I don't. I just simplified my findings for the sake of brevity. In my code, I |
You might still be better of accepting an enum of |
Since I figured out the currently fastest way to get a vec, I consider this issue closed now. Should I make a new issue for the |
Personally, I am not sure I consider it a problem as the iterator is most likely not the only place where |
If you do, please explain clearly and with at least one code example. |
If you want to teach people how to use ndarrays most efficiently, I would suggest writing documentation or changing the API to make |
Hi! I wanted to know what's the fastest way to convert a
PyReadonlyArrayDyn<f32>
into aVec<f32>
.I'm making python bindings for an image processing programs, and converting numpy arrays into a contiguous memory format is the first step. I'm already using
ndarray.as_slice()
which allows me to skip the conversion to vec. This issue is about indexed ndarrays. I'm currently using the following code for the conversion:Compared to a
slice.to_vec()
, this is more than 10x slower. Running this code on a (4320, 8468, 4) ndarray takes 0.2sec if the array is a slice (so it runsslice.to_vec()
) and 3sec when the array is indexed (I cropped off 1px on the left side).This is a huge performance cliff for me, so I would like to know what I can do to fix this.
The text was updated successfully, but these errors were encountered: