| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2d74318 commit e24ee72
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ Python bindings for the [xtensor](https://github.com/QuantStack/xtensor) C++ mul | |||
| 10 | 10 | - `xtensor` is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing. | |
| 11 | 11 | - `xtensor-python` enables inplace use of numpy arrays in C++ with all the benefits from `xtensor` | |
| 12 | 12 | ||
| 13 | - - C++ universal function and broadcasting | ||
| 13 | + - C++ universal function and broadcasting | ||
| 14 | 14 | - STL - compliant APIs. | |
| 15 | 15 | - A broad coverage of numpy APIs (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)). | |
| 16 | 16 | ||
@@ -54,14 +54,12 @@ double sum_of_sines(xt::pyarray<double>& m) | |||
| 54 | 54 | return std::accumulate(sines.begin(), sines.end(), 0.0); | |
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | - PYBIND11_PLUGIN(xtensor_python_test) | ||
| 57 | + PYBIND11_MODULE(xtensor_python_test, m) | ||
| 58 | 58 | { | |
| 59 | 59 | xt::import_numpy(); | |
| 60 | - pybind11::module m("xtensor_python_test", "Test module for xtensor python bindings"); | ||
| 60 | + m.doc() = "Test module for xtensor python bindings"; | ||
| 61 | 61 | ||
| 62 | 62 | m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values"); | |
| 63 | - | ||
| 64 | - return m.ptr(); | ||
| 65 | 63 | } | |
| 66 | 64 | ``` | |
| 67 | 65 | ||
@@ -80,7 +78,7 @@ s | |||
| 80 | 78 | ||
| 81 | 79 | ``` | |
| 82 | 80 | 1.2853996391883833 | |
| 83 | - ``` | ||
| 81 | + ``` | ||
| 84 | 82 | ||
| 85 | 83 | ### Example 2: Create a universal function from a C++ scalar function | |
| 86 | 84 | ||
@@ -99,13 +97,11 @@ double scalar_func(double i, double j) | |||
| 99 | 97 | return std::sin(i) - std::cos(j); | |
| 100 | 98 | } | |
| 101 | 99 | ||
| 102 | - PYBIND11_PLUGIN(xtensor_python_test) | ||
| 100 | + PYBIND11_MODULE(xtensor_python_test, m) | ||
| 103 | 101 | { | |
| 104 | - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); | ||
| 102 | + m.doc() = "Test module for xtensor python bindings"; | ||
| 105 | 103 | ||
| 106 | 104 | m.def("vectorized_func", xt::pyvectorize(scalar_func), ""); | |
| 107 | - | ||
| 108 | - return m.ptr(); | ||
| 109 | 105 | } | |
| 110 | 106 | ``` | |
| 111 | 107 | ||
@@ -127,7 +123,7 @@ z | |||
| 127 | 123 | [[-0.540302, 1.257618, 1.89929 , 0.794764, -1.040465], | |
| 128 | 124 | [-1.499227, 0.136731, 1.646979, 1.643002, 0.128456], | |
| 129 | 125 | [-1.084323, -0.583843, 0.45342 , 1.073811, 0.706945]] | |
| 130 | - ``` | ||
| 126 | + ``` | ||
| 131 | 127 | ||
| 132 | 128 | ## Installation | |
| 133 | 129 | ||
@@ -155,7 +151,7 @@ Testing `xtensor-python` requires `pytest` | |||
| 155 | 151 | py.test . | |
| 156 | 152 | ``` | |
| 157 | 153 | ||
| 158 | - To pick up changes in `xtensor-python` while rebuilding, delete the `build/` directory. | ||
| 154 | + To pick up changes in `xtensor-python` while rebuilding, delete the `build/` directory. | ||
| 159 | 155 | ||
| 160 | 156 | ## Building the HTML Documentation | |
| 161 | 157 | ||
@@ -169,7 +165,7 @@ While doxygen must be installed separately, you can install breathe by typing | |||
| 169 | 165 | ||
| 170 | 166 | ```bash | |
| 171 | 167 | pip install breathe | |
| 172 | - ``` | ||
| 168 | + ``` | ||
| 173 | 169 | ||
| 174 | 170 | Breathe can also be installed with `conda` | |
| 175 | 171 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,15 +12,15 @@ using complex_t = std::complex<double>; | |||
| 12 | 12 | ||
| 13 | 13 | namespace py = pybind11; | |
| 14 | 14 | ||
| 15 | - PYBIND11_PLUGIN(benchmark_xtensor_python) | ||
| 15 | + PYBIND11_MODULE(benchmark_xtensor_python, m) | ||
| 16 | 16 | { | |
| 17 | 17 | if(_import_array() < 0) | |
| 18 | 18 | { | |
| 19 | 19 | PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); | |
| 20 | 20 | return nullptr; | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | - py::module m("benchmark_xtensor_python", "Benchmark module for xtensor python bindings"); | ||
| 23 | + m.doc() = "Benchmark module for xtensor python bindings"; | ||
| 24 | 24 | ||
| 25 | 25 | m.def("sum_array", [](xt::pyarray<double> const& x) { | |
| 26 | 26 | double sum = 0; | |
@@ -55,6 +55,4 @@ PYBIND11_PLUGIN(benchmark_xtensor_python) | |||
| 55 | 55 | else | |
| 56 | 56 | throw py::type_error("rect_to_polar unhandled type"); | |
| 57 | 57 | }); | |
| 58 | - | ||
| 59 | - return m.ptr(); | ||
| 60 | 58 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,14 +26,12 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace | |||
| 26 | 26 | return std::accumulate(sines.cbegin(), sines.cend(), 0.0); | |
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | - PYBIND11_PLUGIN(xtensor_python_test) | ||
| 29 | + PYBIND11_MODULE(xtensor_python_test, m) | ||
| 30 | 30 | { | |
| 31 | 31 | xt::import_numpy(); | |
| 32 | - pybind11::module m("xtensor_python_test", "Test module for xtensor python bindings"); | ||
| 32 | + m.doc() = "Test module for xtensor python bindings"; | ||
| 33 | 33 | ||
| 34 | 34 | m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values"); | |
| 35 | - | ||
| 36 | - return m.ptr(); | ||
| 37 | 35 | } | |
| 38 | 36 | ||
| 39 | 37 | **Python code:** | |
@@ -74,14 +72,12 @@ Example 2: Create a numpy-style universal function from a C++ scalar function | |||
| 74 | 72 | return std::sin(i) - std::cos(j); | |
| 75 | 73 | } | |
| 76 | 74 | ||
| 77 | - PYBIND11_PLUGIN(xtensor_python_test) | ||
| 75 | + PYBIND11_MODULE(xtensor_python_test, m) | ||
| 78 | 76 | { | |
| 79 | 77 | xt::import_numpy(); | |
| 80 | - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); | ||
| 78 | + m.doc() = "Test module for xtensor python bindings"; | ||
| 81 | 79 | ||
| 82 | 80 | m.def("vectorized_func", xt::pyvectorize(scalar_func), ""); | |
| 83 | - | ||
| 84 | - return m.ptr(); | ||
| 85 | 81 | } | |
| 86 | 82 | ||
| 87 | 83 | **Python code:** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,12 +27,10 @@ Thus the basic skeleton of the module looks like: | |||
| 27 | 27 | #define FORCE_IMPORT_ARRAY | |
| 28 | 28 | #include "xtensor-python/pyarray.hpp" | |
| 29 | 29 | ||
| 30 | - PYBIND11_PLUGIN(plugin_name) | ||
| 30 | + PYBIND11_MODULE(plugin_name, m) | ||
| 31 | 31 | { | |
| 32 | 32 | xt::import_numpy(); | |
| 33 | - pybind11::module m(//... | ||
| 34 | 33 | //... | |
| 35 | - return m.ptr(); | ||
| 36 | 34 | } | |
| 37 | 35 | ||
| 38 | 36 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,11 +107,11 @@ void dump_numpy_constant() | |||
| 107 | 107 | std::cout << "NPY_UINT64 = " << NPY_UINT64 << std::endl; | |
| 108 | 108 | } | |
| 109 | 109 | ||
| 110 | - PYBIND11_PLUGIN(xtensor_python_test) | ||
| 110 | + PYBIND11_MODULE(xtensor_python_test, m) | ||
| 111 | 111 | { | |
| 112 | 112 | xt::import_numpy(); | |
| 113 | 113 | ||
| 114 | - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); | ||
| 114 | + m.doc() = "Test module for xtensor python bindings"; | ||
| 115 | 115 | ||
| 116 | 116 | m.def("example1", example1); | |
| 117 | 117 | m.def("example2", example2); | |
@@ -142,6 +142,4 @@ PYBIND11_PLUGIN(xtensor_python_test) | |||
| 142 | 142 | m.def("int_overload", int_overload<int64_t>); | |
| 143 | 143 | ||
| 144 | 144 | m.def("dump_numpy_constant", dump_numpy_constant); | |
| 145 | - | ||
| 146 | - return m.ptr(); | ||
| 147 | 145 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments