-
Notifications
You must be signed in to change notification settings - Fork 51
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
Using preallocated buffers in python #1466
Comments
Btw, @ax3l do you have any idea how this works with |
This seems weird. The above code usually should run into an even more subtle error. The underlying problem is that a line such as I really don't know what causes the ValueError that you see, though.
The documentation status of our Python bindings is a bit unfortunate, yes #1328
I think that your last suggestion should be relatively straightforward to implement given the helper functions that we already have in the Python bindings. I would prefer a solution that would help us avoid the above trap though. One third workaround suggestion: Add a helper class io.LoadToArray(array)[:, :, :] = mrc[:, :, :]
# ... would resolve to:
mrc.load_chunk(array, [0, 0, 0], […]) |
Thinking further about it, I think that it's a somewhat unfortunate API choice that something like Compare our implementation of the A while ago, @ax3l suggested that we add a synchronous (~safe) mode for the Python API. This mode would require no explicit flushing, but rather flush upon every operation. I suggest a solution to this issue built on such a mode:
|
I like the synchronous default in python. I think most of the time, that I was helping someone with the api, they were not flushing, or flushing at a wrong position. A missing |
Problem
Hi! I was often running into the situation where I wanted to do sth like that:
So, reading different chunks to different parts of a predefined
numpy
array.But this fails with:
ValueError: vector::_M_default_append
There seams to exists an, as far as I know, undocumented workaround, that I just found:
As the
MeshRecordComponent.load_chunk
method can take something providing the python buffer interface as an extra argument. But this is not that easy to use as with the slicing syntax and the[ ]
operator.Possible solution
It would be fantastic if sth like this
a[0, :, :, :] = example_mrc[240:242, :, 100:200]
could work, but I'm not sure how one would change the function execution based on the object on the left-hand side (thoughnumpy
broadcasting seams to do it somehow).Alternatively, one could have a new
MeshRecordComponent
method returning an object with a__get_item__
method, so that we can use syntax like this:Or maybe, there exists some class that is exposed in python that can be used to convert the slicing syntax to offset and extent? Sth like:
some_mrc.load_chunk(a[0, :, :, :], *io.offset_and_extent_getter[240:242, :, :100:200])
I don't know much about how the python bindings work, otherwise I would implement it myself.
The text was updated successfully, but these errors were encountered: