Skip to content

Commit ac01ec8

Browse files
committed
more updates
1 parent 6a39eed commit ac01ec8

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

content/12-extensions/extensions-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Here's the implementation of our Mandelbrot generator:
250250
We build the shared library as:
251251

252252
```bash
253-
g++ -O3 -Wall -Wextra -shared -std=c++17 -fPIC $(python3 -m pybind11 --includes) mandel.cpp -o mandel$(python3-config --extension-suffix)
253+
g++ -DNDEBUG -O3 -Wall -Wextra -shared -std=c++17 -fPIC $(python3 -m pybind11 --includes) mandel.cpp -o mandel$(python3-config --extension-suffix)
254254
```
255255

256256
Our driver is essentially the same as the Fortran one.

content/12-extensions/extensions-overview.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ and weaknesses.
1919
header-only library that allows you to call C++ functions directly
2020
from python.
2121

22+
A related library is [nanobind](https://github.com/wjakob/nanobind),
23+
which has similar syntax but may be more efficient.
24+
2225
* C
2326

2427
* [C-API](https://docs.python.org/3/c-api/index.html) : the
@@ -33,9 +36,12 @@ and weaknesses.
3336
represent the arrays we use. This means writing a lot of
3437
boilerplate code just to deal with some simple operations.
3538

36-
This underlies most of the techniques that we'll see here.
39+
This underlies many of the techniques that we'll see here.
40+
41+
.. note::
3742

38-
These days, there are better methods for most applications.
43+
These days, there are better methods for most applications,
44+
and you should probably not use the C-API directly.
3945

4046
* [ctypes](https://docs.python.org/3/library/ctypes.html) : this
4147
is a module that allows you to call functions in shared libraries.

examples/extensions/pybind11/contiguous/mandel.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#include <iostream>
1+
#include <cstddef>
22
#include <cmath>
33
#include <complex>
4-
#include <vector>
54

65
#include <pybind11/pybind11.h>
76
#include <pybind11/numpy.h>
@@ -33,9 +32,9 @@ py::array_t<int> mandelbrot(int N,
3332
// construct the numpy array we will return
3433
// we need to specify the strides manually
3534

36-
constexpr size_t elsize = sizeof(int);
37-
size_t shape[2]{N, N};
38-
size_t strides[2]{N * elsize, elsize};
35+
constexpr std::size_t elsize = sizeof(int);
36+
std::size_t shape[2]{N, N};
37+
std::size_t strides[2]{N * elsize, elsize};
3938
auto m = py::array_t<int>(shape, strides);
4039
auto m_view = m.mutable_unchecked<2>();
4140

examples/extensions/pybind11/mandel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ py::array_t<int> mandelbrot(int N,
2121
// construct the numpy array we will return
2222
// we need to specify the strides manually
2323

24-
constexpr size_t elsize = sizeof(int);
25-
size_t shape[2]{N, N};
26-
size_t strides[2]{N * elsize, elsize};
24+
constexpr std::size_t elsize = sizeof(int);
25+
std::size_t shape[2]{N, N};
26+
std::size_t strides[2]{N * elsize, elsize};
2727
auto m = py::array_t<int>(shape, strides);
2828
auto m_view = m.mutable_unchecked<2>();
2929

0 commit comments

Comments
 (0)