Skip to content
Permalink
Browse files

adding cython text

  • Loading branch information...
derekmolloy committed May 17, 2018
1 parent 25f33b5 commit efb5987bb724210bae7f980925f6f00fe68961c4
@@ -0,0 +1,24 @@
#include<string>
#include<boost/python.hpp> // .hpp convention for c++ headers
using namespace std; // just like cpp for source files

namespace exploringbb{ // keep the global namespace clean

string hello(string name) { // e.g., returns "Hello Derek!"
return ("Hello " + name + "!");
}

double integrate(double a, double b, int n) { // same as before
double sum=0, dx = (b-a)/n;
for(int i=0; i<n; i++){ sum += sin((a+i)*dx); }
return sum*dx;
}
}

BOOST_PYTHON_MODULE(ebb){ // the module is called ebb
using namespace boost::python; // require the boost.python namespace
using namespace exploringbb; // bring in custom namespace
def("hello", hello); // make hello() visible to Python
def("integrate", integrate); // make integrate() also visible
}

BIN +29.4 KB chp05/boost/ebb.so
Binary file not shown.
@@ -0,0 +1,10 @@
#!/usr/bin/python
# A Python program that calls C program code
import ebb

print "Start of the Python program"
print ebb.hello("Derek")
val = ebb.integrate(0, 3.14159, 1000000)
print "The integral result is: ", val
print "End of the Python program"

@@ -0,0 +1,11 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("test", ["test.pyx"])]
setup(
name = 'random number sum application',
cmdclass = {'build_ext' : build_ext },
ext_modules = ext_modules
)

Oops, something went wrong.

0 comments on commit efb5987

Please sign in to comment.
You can’t perform that action at this time.