From e24ee72b9c05153409c854c12e18f0cde733ff84 Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Wed, 24 Jan 2018 22:34:23 +0100 Subject: [PATCH] Update deprecated macro --- README.md | 22 +++++++++------------- benchmark/main.cpp | 6 ++---- docs/source/basic_usage.rst | 12 ++++-------- docs/source/numpy_capi.rst | 4 +--- test_python/main.cpp | 6 ++---- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 02d9842..7852274 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Python bindings for the [xtensor](https://github.com/QuantStack/xtensor) C++ mul - `xtensor` is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing. - `xtensor-python` enables inplace use of numpy arrays in C++ with all the benefits from `xtensor` - - C++ universal function and broadcasting + - C++ universal function and broadcasting - STL - compliant APIs. - A broad coverage of numpy APIs (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)). @@ -54,14 +54,12 @@ double sum_of_sines(xt::pyarray& m) return std::accumulate(sines.begin(), sines.end(), 0.0); } -PYBIND11_PLUGIN(xtensor_python_test) +PYBIND11_MODULE(xtensor_python_test, m) { xt::import_numpy(); - pybind11::module m("xtensor_python_test", "Test module for xtensor python bindings"); + m.doc() = "Test module for xtensor python bindings"; m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values"); - - return m.ptr(); } ``` @@ -80,7 +78,7 @@ s ``` 1.2853996391883833 -``` +``` ### Example 2: Create a universal function from a C++ scalar function @@ -99,13 +97,11 @@ double scalar_func(double i, double j) return std::sin(i) - std::cos(j); } -PYBIND11_PLUGIN(xtensor_python_test) +PYBIND11_MODULE(xtensor_python_test, m) { - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); + m.doc() = "Test module for xtensor python bindings"; m.def("vectorized_func", xt::pyvectorize(scalar_func), ""); - - return m.ptr(); } ``` @@ -127,7 +123,7 @@ z [[-0.540302, 1.257618, 1.89929 , 0.794764, -1.040465], [-1.499227, 0.136731, 1.646979, 1.643002, 0.128456], [-1.084323, -0.583843, 0.45342 , 1.073811, 0.706945]] -``` +``` ## Installation @@ -155,7 +151,7 @@ Testing `xtensor-python` requires `pytest` py.test . ``` -To pick up changes in `xtensor-python` while rebuilding, delete the `build/` directory. +To pick up changes in `xtensor-python` while rebuilding, delete the `build/` directory. ## Building the HTML Documentation @@ -169,7 +165,7 @@ While doxygen must be installed separately, you can install breathe by typing ```bash pip install breathe -``` +``` Breathe can also be installed with `conda` diff --git a/benchmark/main.cpp b/benchmark/main.cpp index c72fe6a..c5c143b 100644 --- a/benchmark/main.cpp +++ b/benchmark/main.cpp @@ -12,7 +12,7 @@ using complex_t = std::complex; namespace py = pybind11; -PYBIND11_PLUGIN(benchmark_xtensor_python) +PYBIND11_MODULE(benchmark_xtensor_python, m) { if(_import_array() < 0) { @@ -20,7 +20,7 @@ PYBIND11_PLUGIN(benchmark_xtensor_python) return nullptr; } - py::module m("benchmark_xtensor_python", "Benchmark module for xtensor python bindings"); + m.doc() = "Benchmark module for xtensor python bindings"; m.def("sum_array", [](xt::pyarray const& x) { double sum = 0; @@ -55,6 +55,4 @@ PYBIND11_PLUGIN(benchmark_xtensor_python) else throw py::type_error("rect_to_polar unhandled type"); }); - - return m.ptr(); } diff --git a/docs/source/basic_usage.rst b/docs/source/basic_usage.rst index 6a7b856..c97c9ac 100644 --- a/docs/source/basic_usage.rst +++ b/docs/source/basic_usage.rst @@ -26,14 +26,12 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace return std::accumulate(sines.cbegin(), sines.cend(), 0.0); } - PYBIND11_PLUGIN(xtensor_python_test) + PYBIND11_MODULE(xtensor_python_test, m) { xt::import_numpy(); - pybind11::module m("xtensor_python_test", "Test module for xtensor python bindings"); + m.doc() = "Test module for xtensor python bindings"; m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values"); - - return m.ptr(); } **Python code:** @@ -74,14 +72,12 @@ Example 2: Create a numpy-style universal function from a C++ scalar function return std::sin(i) - std::cos(j); } - PYBIND11_PLUGIN(xtensor_python_test) + PYBIND11_MODULE(xtensor_python_test, m) { xt::import_numpy(); - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); + m.doc() = "Test module for xtensor python bindings"; m.def("vectorized_func", xt::pyvectorize(scalar_func), ""); - - return m.ptr(); } **Python code:** diff --git a/docs/source/numpy_capi.rst b/docs/source/numpy_capi.rst index 2a7c458..aa0855f 100644 --- a/docs/source/numpy_capi.rst +++ b/docs/source/numpy_capi.rst @@ -27,12 +27,10 @@ Thus the basic skeleton of the module looks like: #define FORCE_IMPORT_ARRAY #include "xtensor-python/pyarray.hpp" - PYBIND11_PLUGIN(plugin_name) + PYBIND11_MODULE(plugin_name, m) { xt::import_numpy(); - pybind11::module m(//... //... - return m.ptr(); } diff --git a/test_python/main.cpp b/test_python/main.cpp index 58b7d69..84c4cb2 100644 --- a/test_python/main.cpp +++ b/test_python/main.cpp @@ -107,11 +107,11 @@ void dump_numpy_constant() std::cout << "NPY_UINT64 = " << NPY_UINT64 << std::endl; } -PYBIND11_PLUGIN(xtensor_python_test) +PYBIND11_MODULE(xtensor_python_test, m) { xt::import_numpy(); - py::module m("xtensor_python_test", "Test module for xtensor python bindings"); + m.doc() = "Test module for xtensor python bindings"; m.def("example1", example1); m.def("example2", example2); @@ -142,6 +142,4 @@ PYBIND11_PLUGIN(xtensor_python_test) m.def("int_overload", int_overload); m.def("dump_numpy_constant", dump_numpy_constant); - - return m.ptr(); }