[C++-sig] Newbie : fastest way of sending floats
Philip Austin
paustin at eos.ubc.ca
Thu Nov 20 18:33:25 CET 2003
Benjamin Golinvaux writes:
>
> I am not looking for the cleanest code, but for the FASTEST way to pass
> the array of floats. I am willing to use the raw C api if needed.
The fastest way to pass an array of floats is to use Numerical Python
(http://www.pfdubois.com/numpy). Boost supports conversions between
numpy (and its eventual successor, numarray) and python. Here's an example of
a wrapper for a spline interpolator, which also makes use of a
boost/numpy support library available at
http://www.eos.ubc.ca/research/clouds/num_util.html
py::numeric::array splinewrap(py::numeric::array x, py::numeric::array y,
double yp1, double ypn)
{
nbpl::check_rank(x,1);
nbpl::check_type(x,PyArray_DOUBLE);
int xsize=nbpl::size(x);
nbpl::check_rank(y,1);
nbpl::check_type(y,PyArray_DOUBLE);
int ysize=nbpl::size(y);
assert(xsize==ysize);
double* xptr=(double*) nbpl::data(x);
double* yptr=(double*) nbpl::data(y);
py::numeric::array y2=nbpl::makeNum(ysize, PyArray_DOUBLE);
double* y2ptr=(double*) nbpl::data(y2);
spline(xptr,yptr,ysize,yp1,ypn,y2ptr);
return y2;
}
Regards, Phil
More information about the Cplusplus-sig
mailing list