★ wanayoo — archive 1999 https://github.com/xtensor-stack/xtensor-python/pull/175Nouvelle recherche | Portail wanayoo
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

Add an example for sharing the memory buffer of the xarray between C++ and Python (numpy) #175

Merged
merged 3 commits into from Nov 6, 2018

Conversation

@yungyuc
Copy link
Contributor

yungyuc commented Nov 2, 2018

#113 added the ability to take the memory buffer of an xarray and share it with ndarray in Python, but there wasn't an example for how to do it. This PR adds an example in the pytest directory.

I also fixed some formatting and compatibilty issue with pybind11 2.3.

yungyuc added 2 commits Nov 2, 2018
Demonstrate how to return an array and share the buffer to Python (numpy).
@yungyuc
Copy link
Contributor Author

yungyuc commented Nov 2, 2018

I originally thought numpy view binding (#130) is necessary, but it turned out the feature I needed is already in the code base.

@yungyuc
Copy link
Contributor Author

yungyuc commented Nov 5, 2018

Would someone be willing to take a look at this? If the fixes for pybind11 2.3 should be in a separate PR, I can close this and file two new ones.

@SylvainCorlay
Copy link
Member

SylvainCorlay commented Nov 5, 2018

@yungyuc sorry for the late reply! I am looking at it now.

@@ -12,6 +12,7 @@

#include "pybind11/numpy.h"

#include "xtensor/xarray.hpp"

This comment has been minimized.

@SylvainCorlay

SylvainCorlay Nov 5, 2018

Member

Is this required?

This comment has been minimized.

@yungyuc

yungyuc Nov 5, 2018

Author Contributor

Yes. On OSX if commenting it out, I got:

In file included from /Users/yungyuc/hack/code/xtensor-python/test/main.cpp:17:
In file included from /Users/yungyuc/hack/code/xtensor-python/include/xtensor-python/pyarray.hpp:17:
/Users/yungyuc/hack/usr/opt36_180914/include/xtensor/xiterator.hpp:406:25: error: no member named 'mpl' in namespace 'xtl'
            return xtl::mpl::static_if<has_storage_iterator<C>::value>([&](auto self)
                   ~~~~~^

This comment has been minimized.

@SylvainCorlay

SylvainCorlay Nov 5, 2018

Member

Hum, this seems to be something that was fixed about 2 months ago in xtensor-stack/xtensor@8a61692.

This comment has been minimized.

@yungyuc

yungyuc Nov 6, 2018

Author Contributor

You are right. I was testing against xtensor-stack/xtensor@18a26c8 (Fri Sep 14 15:55:58 2018 +0200). After updating xtensor to the latest master (xtensor-stack/xtensor@d61b71e) I don't need this line anymore. I'll remove it.

This comment has been minimized.

@SylvainCorlay

SylvainCorlay Nov 6, 2018

Member

@yungyuc excellent!

(By the way, is there a specific reason why you are running on specific commits and not version tags?)

This comment has been minimized.

@yungyuc

yungyuc Nov 6, 2018

Author Contributor

@SylvainCorlay It's only because of my careless practice. My time on my side project is limited so I am developing against master of primary dependencies (pybind11, xtensor, xtensor-python, etc.). It's fine but sometimes (like this time) I was distracted for weeks and forgot to update the dependencies.

Sorry for my silly mistake. I've add a new change reverting this line and other two spots of unnecessary change.

@@ -8,11 +8,11 @@

#include "gtest/gtest.h"

#include "xtensor-python/pyarray.hpp"

This comment has been minimized.

@yungyuc

yungyuc Nov 6, 2018

Author Contributor

This is reverted in a newer change.

@@ -8,11 +8,11 @@

#include "gtest/gtest.h"

#include "xtensor-python/pytensor.hpp"

This comment has been minimized.

@yungyuc

yungyuc Nov 6, 2018

Author Contributor

This is reverted in a newer change.

@JohanMabille JohanMabille merged commit 7f96473 into xtensor-stack:master Nov 6, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@yungyuc yungyuc deleted the yungyuc:array-ref branch Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.