-
Notifications
You must be signed in to change notification settings - Fork 26
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
Implement Python buffer protocol. #238
Conversation
Hi, Thanks for these changes. They look good to me, with just one caveat: As is done in the other Cheers, |
uhal/uhal/src/common/ValMem.cpp
Outdated
template< typename T > | ||
T* ValVector< T >::data() const | ||
{ | ||
return mMembers->value.data(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this implementation to:
if ( mMembers->valid )
{
return mMembers->value.data();
}
else
{
exception::NonValidatedMemory lExc;
log ( lExc , "Access attempted on non-validated memory" );
throw lExc;
}
uhal/uhal/include/uhal/ValMem.hpp
Outdated
Return the address of the underlying memory | ||
@return the address of the underlying memory | ||
*/ | ||
T* data() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the return type to const T*
(to match the return type constness of the std::vector
data() const
method)
I implemented the requested changes, but I cannot test them right now. Unfortunately the hardware we are using this with died last Friday. I will check it a soon as it works again, but feel free to merge anyway if you think the changes look good. |
Anything else keeping this from being included? |
Hi @ast0815 Sorry for the delay in merging this. I rebased this branch against the master branch a couple of days ago, and added some related tests to reduce the chances of breaking this in the future. I've now merged those changes in through another pull request - #253 - and created a new tag containing these changes: Cheers, |
Hello,
I am currently working on a piece of DAQ software that uses the Python
uhal
bindings. Performance is an issue, so I tried to get the data transfer into the Python environment as fast as possible.For this, I implemented the "buffer protocol" which allows Python objects to access each others underlying memory. It makes e.g. conversions of the read out ValVectors into Numpy arrays much much faster.
I tried converting the ValVector directly
arr = np.array(valvector)
or via thevalue
methodarr = np.array(valvector.value())
.Without my patch:
With my patch:
As you can see, when the buffer protocol is implemented, a direct conversion to an array happens pretty much instantaneously, since the memory does not even have to be copied.
Please let me know what you think!