★ wanayoo — archive 1999 https://github.com/xtensor-stack/xtensor-python/issues/158Nouvelle 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

Doc: add a section for code exposed to both C++ and python #158

Open
JohanMabille opened this issue Jul 26, 2018 · 4 comments
Open

Doc: add a section for code exposed to both C++ and python #158

JohanMabille opened this issue Jul 26, 2018 · 4 comments
Labels

Comments

@JohanMabille
Copy link
Member

@JohanMabille JohanMabille commented Jul 26, 2018

This section should describe the best practices when functions need to be exposed to both C++ (operating on xtensor / xarray) and Python (operating on pytensor / pyarray)

@pelson
Copy link
Contributor

@pelson pelson commented Sep 17, 2018

Are there any examples of doing this anywhere I could take a look at?

@JohanMabille
Copy link
Member Author

@JohanMabille JohanMabille commented Sep 17, 2018

You can find an example here. The idea is to put the code in dedicated headers and cpp files that can be compiled in C++ mode only, and to expose them to the python in a single cpp module file.

@zhujun98
Copy link
Contributor

@zhujun98 zhujun98 commented Jul 17, 2019

I am a new xtensor-python user and I found the above example code is nice. However, most of them are related to pyvectorize.

It would be nice if more use cases could be included. For example, I want to modify an numpy.array in-place and I have the following piece of code:

template<typename T>
inline void movingAverage(xt::pyarray<T>& ma, const xt::pyarray<T>& data, size_t count) {
  ma = ma + (data - ma) / T(count);
}

However, on the Python side, I cannot see the change. If I change xt::pyarray to xt::xarray and run the function only in C++, it works. Could you please let me know how to make the Python binding work? Thank you!

@SylvainCorlay
Copy link
Member

@SylvainCorlay SylvainCorlay commented Jul 17, 2019

However, on the Python side, I cannot see the change

This appears to be a legitimate bug. Will be getting back to you shortly with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.