Skip to content

Commit e24ee72

Browse files
committed
Update deprecated macro
1 parent 2d74318 commit e24ee72

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Python bindings for the [xtensor](https://github.com/QuantStack/xtensor) C++ mul
1010
- `xtensor` is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing.
1111
- `xtensor-python` enables inplace use of numpy arrays in C++ with all the benefits from `xtensor`
1212

13-
- C++ universal function and broadcasting
13+
- C++ universal function and broadcasting
1414
- STL - compliant APIs.
1515
- A broad coverage of numpy APIs (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)).
1616

@@ -54,14 +54,12 @@ double sum_of_sines(xt::pyarray<double>& m)
5454
return std::accumulate(sines.begin(), sines.end(), 0.0);
5555
}
5656

57-
PYBIND11_PLUGIN(xtensor_python_test)
57+
PYBIND11_MODULE(xtensor_python_test, m)
5858
{
5959
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";
6161

6262
m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values");
63-
64-
return m.ptr();
6563
}
6664
```
6765
@@ -80,7 +78,7 @@ s
8078

8179
```
8280
1.2853996391883833
83-
```
81+
```
8482

8583
### Example 2: Create a universal function from a C++ scalar function
8684

@@ -99,13 +97,11 @@ double scalar_func(double i, double j)
9997
return std::sin(i) - std::cos(j);
10098
}
10199

102-
PYBIND11_PLUGIN(xtensor_python_test)
100+
PYBIND11_MODULE(xtensor_python_test, m)
103101
{
104-
py::module m("xtensor_python_test", "Test module for xtensor python bindings");
102+
m.doc() = "Test module for xtensor python bindings";
105103

106104
m.def("vectorized_func", xt::pyvectorize(scalar_func), "");
107-
108-
return m.ptr();
109105
}
110106
```
111107
@@ -127,7 +123,7 @@ z
127123
[[-0.540302, 1.257618, 1.89929 , 0.794764, -1.040465],
128124
[-1.499227, 0.136731, 1.646979, 1.643002, 0.128456],
129125
[-1.084323, -0.583843, 0.45342 , 1.073811, 0.706945]]
130-
```
126+
```
131127

132128
## Installation
133129

@@ -155,7 +151,7 @@ Testing `xtensor-python` requires `pytest`
155151
py.test .
156152
```
157153

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.
159155

160156
## Building the HTML Documentation
161157

@@ -169,7 +165,7 @@ While doxygen must be installed separately, you can install breathe by typing
169165

170166
```bash
171167
pip install breathe
172-
```
168+
```
173169

174170
Breathe can also be installed with `conda`
175171

benchmark/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ using complex_t = std::complex<double>;
1212

1313
namespace py = pybind11;
1414

15-
PYBIND11_PLUGIN(benchmark_xtensor_python)
15+
PYBIND11_MODULE(benchmark_xtensor_python, m)
1616
{
1717
if(_import_array() < 0)
1818
{
1919
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
2020
return nullptr;
2121
}
2222

23-
py::module m("benchmark_xtensor_python", "Benchmark module for xtensor python bindings");
23+
m.doc() = "Benchmark module for xtensor python bindings";
2424

2525
m.def("sum_array", [](xt::pyarray<double> const& x) {
2626
double sum = 0;
@@ -55,6 +55,4 @@ PYBIND11_PLUGIN(benchmark_xtensor_python)
5555
else
5656
throw py::type_error("rect_to_polar unhandled type");
5757
});
58-
59-
return m.ptr();
6058
}

docs/source/basic_usage.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace
2626
return std::accumulate(sines.cbegin(), sines.cend(), 0.0);
2727
}
2828
29-
PYBIND11_PLUGIN(xtensor_python_test)
29+
PYBIND11_MODULE(xtensor_python_test, m)
3030
{
3131
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";
3333
3434
m.def("sum_of_sines", sum_of_sines, "Sum the sines of the input values");
35-
36-
return m.ptr();
3735
}
3836
3937
**Python code:**
@@ -74,14 +72,12 @@ Example 2: Create a numpy-style universal function from a C++ scalar function
7472
return std::sin(i) - std::cos(j);
7573
}
7674
77-
PYBIND11_PLUGIN(xtensor_python_test)
75+
PYBIND11_MODULE(xtensor_python_test, m)
7876
{
7977
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";
8179
8280
m.def("vectorized_func", xt::pyvectorize(scalar_func), "");
83-
84-
return m.ptr();
8581
}
8682
8783
**Python code:**

docs/source/numpy_capi.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ Thus the basic skeleton of the module looks like:
2727
#define FORCE_IMPORT_ARRAY
2828
#include "xtensor-python/pyarray.hpp"
2929
30-
PYBIND11_PLUGIN(plugin_name)
30+
PYBIND11_MODULE(plugin_name, m)
3131
{
3232
xt::import_numpy();
33-
pybind11::module m(//...
3433
//...
35-
return m.ptr();
3634
}
3735
3836

test_python/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ void dump_numpy_constant()
107107
std::cout << "NPY_UINT64 = " << NPY_UINT64 << std::endl;
108108
}
109109

110-
PYBIND11_PLUGIN(xtensor_python_test)
110+
PYBIND11_MODULE(xtensor_python_test, m)
111111
{
112112
xt::import_numpy();
113113

114-
py::module m("xtensor_python_test", "Test module for xtensor python bindings");
114+
m.doc() = "Test module for xtensor python bindings";
115115

116116
m.def("example1", example1);
117117
m.def("example2", example2);
@@ -142,6 +142,4 @@ PYBIND11_PLUGIN(xtensor_python_test)
142142
m.def("int_overload", int_overload<int64_t>);
143143

144144
m.def("dump_numpy_constant", dump_numpy_constant);
145-
146-
return m.ptr();
147145
}

0 commit comments

Comments
 (0)