Weave
=====
Weave is a tool that does for C/C++ what f2py does for fortran
(though we should note it is also possible to wrap C code using
f2py). Suppose we have some data stored in numpy arrays and we want
to write some C/C++ code to do something with that data that needs
to be fast. For a trivial example, let us write a function that
sums the contents of a numpy array
::
sage: from scipy import weave
sage: from scipy.weave import converters
::
def my_sum(a):
n=int(len(a))
code="""
int i;
long int counter;
counter =0;
for(i=0;i
extern "C" {
void dgesv_(int *size, int *flag,double* data,int*size,
int*perm,double*vec,int*size,int*ok);
}
"""
code="""
int i,j;
double* a_c;
double* b_c;
int size;
int flag;
int* p;
int ok;
size=n;
flag=1;
a_c= (double *)malloc(sizeof(double)*n*n);
b_c= (double *)malloc(sizeof(double)*n);
p = (int*)malloc(sizeof(int)*n);
for(i=0;i