[C++-sig] Blitz++ and boost.python and Pyste ...
Philip Austin
paustin at eos.ubc.ca
Thu Apr 17 18:16:43 CEST 2003
> For example, how can get a blitz::Array<complex<float>,1> into my python
> interpreter ? Any idea
> on how and where to start woul be really appreciated...
>
Here's one way to do something similar for a contiguous n-dimensional
array of doubles:
numeric::array makeNum(double * data, std::vector<int> dims){
int total = 1;
std::vector<int>::iterator iter = dims.begin();
while(iter != dims.end()){
total *= *iter;
++iter;
}
object obj(handle<>(PyArray_FromDims(dims.size(),&dims[0], PyArray_DOUBLE)));
char *arr_data = ((PyArrayObject*) obj.ptr())->data;
memcpy(arr_data, data, sizeof(double) * total);
return extract<numeric::array>(obj);
}
The data pointer would be pointing to the beginning of the Blitz
array. boost::python::numeric::array is a registered type
that wraps a Numeric Python array. We have some example code and
a set of utility functions that demonstrate this approach, and will
put them up in the next day or so -- regards, Phil
More information about the Cplusplus-sig
mailing list