- Notifications
You must be signed in to change notification settings - Fork65
Adding possibility to 'cast' or copy toxt::xarray
etc#266
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions.azure-pipelines/unix-build.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletionsdocs/source/examples/copy_cast/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.1..3.19) | ||
project(mymodule) | ||
find_package(pybind11 CONFIG REQUIRED) | ||
find_package(xtensor REQUIRED) | ||
find_package(xtensor-python REQUIRED) | ||
find_package(Python REQUIRED COMPONENTS NumPy) | ||
pybind11_add_module(mymodule main.cpp) | ||
target_link_libraries(mymodule PUBLIC pybind11::module xtensor-python Python::NumPy) | ||
target_compile_definitions(mymodule PRIVATE VERSION_INFO=0.1.0) |
7 changes: 7 additions & 0 deletionsdocs/source/examples/copy_cast/example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import mymodule | ||
import numpy as np | ||
a = np.array([1, 2, 3]) | ||
assert np.isclose(np.sum(np.sin(a)), mymodule.sum_of_sines(a)) | ||
assert np.isclose(np.sum(np.cos(a)), mymodule.sum_of_cosines(a)) | ||
25 changes: 25 additions & 0 deletionsdocs/source/examples/copy_cast/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <numeric> | ||
#include <xtensor.hpp> | ||
#include <pybind11/pybind11.h> | ||
#define FORCE_IMPORT_ARRAY | ||
#include <xtensor-python/pyarray.hpp> | ||
double sum_of_sines(xt::pyarray<double>& m) | ||
{ | ||
auto sines = xt::sin(m); // sines does not actually hold values. | ||
return std::accumulate(sines.begin(), sines.end(), 0.0); | ||
} | ||
double sum_of_cosines(const xt::xarray<double>& m) | ||
{ | ||
auto cosines = xt::cos(m); // cosines does not actually hold values. | ||
return std::accumulate(cosines.begin(), cosines.end(), 0.0); | ||
} | ||
PYBIND11_MODULE(mymodule, m) | ||
{ | ||
xt::import_numpy(); | ||
m.doc() = "Test module for xtensor python bindings"; | ||
m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values"); | ||
m.def("sum_of_cosines", sum_of_cosines, "Sum the cosines of the input values"); | ||
} |
24 changes: 20 additions & 4 deletionsinclude/xtensor-python/xtensor_type_caster_base.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.