#include <boost/numpy.hpp>
#include <boost/scoped_array.hpp>
#include <iostream>
Go to the source code of this file.
Function Documentation
void fill1 |
( |
double * |
array, |
|
|
int |
rows, |
|
|
int |
cols, |
|
|
int |
row_stride, |
|
|
int |
col_stride |
|
) |
| |
A simple example showing how to wrap a couple of C++ functions that operate on 2-d arrays into Python functions that take NumPy arrays as arguments.
If you find have a lot of such functions to wrap, you may want to create a C++ array type (or use one of the many existing C++ array libraries) that maps well to NumPy arrays and create Boost.Python converters. There's more work up front than the approach here, but much less boilerplate per function. See the "Gaussian" example included with Boost.NumPy for an example of custom converters, or take a look at the "ndarray" project on GitHub for a more complete, high-level solution.
Note that we're using embedded Python here only to make a convenient self-contained example; you could just as easily put the wrappers in a regular C++-compiled module and imported them in regular Python. Again, see the Gaussian demo for an example.
Definition at line 36 of file wrap.cpp.
void fill2 |
( |
double ** |
array, |
|
|
int |
rows, |
|
|
int |
cols |
|
) |
| |
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |