Travis Oliphant writes:
> b) byte-the bullet and use Boost python (which other's who have
> integrated C++ code with Python seem to really like). I've never
> wrapped my mind around Boost python, though, so I'm not much help there.
I've updated my set of boost helper functions to work with
numpy -- there's a Readme at:
http://www.eos.ubc.ca/research/clouds/software/pythonlibs/num_util/num_util_release2
(http://tinyurl.com/eo6fe)
A simple example which shows some of the boost python features (reference
counting, C++ versions of python types, docstrings, exceptions)
is appended below. When called with python script http://tinyurl.com/zy57a it
produces the output http://tinyurl.com/fr7xo
Regards, Phil Austin
#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle
#include "num_util.h"
#include <iostream>
namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.2 2006/07/04 01:17:33
phil Exp $"; }
namespace bp=boost::python;
namespace ar=boost::python::numeric;
namespace nbpl = num_util;
//send a dictionary with two arrays back to python
bp::dict testToPython(void){
double ia[6] = {1,2,3,4,5,6};
int ib[3] = {88,99,100};
//construct two numpy arrays
ar::array pyDoubles=nbpl::makeNum(ia,6);
ar::array pyInts=nbpl::makeNum(ib,3);
//pack them in a dictionary and return to python
bp::dict retvals;
retvals["myDoubles"]=pyDoubles;
retvals["myInts"]=pyInts;
return retvals;
}
//get an array from python
void testFromPython(ar::array inValue){
nbpl::check_type(inValue, PyArray_DOUBLE);
nbpl::check_rank(inValue, 2);
double* dataPtr = (double*) nbpl::data(inValue);
int theSize= nbpl::size(inValue);
std::cout << std::endl << "data values on c++ side: " << std::endl;
for(int i=0;i < theSize;++i){
std::cout << *(dataPtr + i) << std::endl;
}
}
BOOST_PYTHON_MODULE(simple_ext)
{
import_array();
ar::array::set_module_and_type("numpy", "ArrayType");
//global doc string
bp::scope().attr("RCSID") = rcsid;
std::string str1;
str1="docstring for module\n";
bp::scope().attr("__doc__") = str1.c_str();
str1 = "Doc string for testToPython\n";
def("testToPython", testToPython,str1.c_str());
str1 = "Doc string for testFromPython\n";
def("testFromPython", testFromPython,str1.c_str());
}
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion