-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25f33b5
commit efb5987
Showing
9 changed files
with
4,000 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.