14.08.2013 Views

Tutorial slides (PDF) - Clemson University

Tutorial slides (PDF) - Clemson University

Tutorial slides (PDF) - Clemson University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Python BLAS Interface<br />

void dscal_(int*n, double* alpha, double* x, int* incx); % C prototype for Fortran<br />

void zscal_(int*n, void* alpha, void* x, int* incx); % C prototype for Fortran<br />

#define DOUBLEP(a) ((double*)((a)->data)) % Casting for NumPy data struc.<br />

#define COMPLEXP(a) ((double_complex*)((a)->data)) % Casting for NumPy data struc.<br />

PyObject* scal(PyObject *self, PyObject *args)<br />

{<br />

Py_complex alpha;<br />

PyArrayObject* x;<br />

if (!PyArg_ParseTuple(args, "DO", &alpha, &x))<br />

return NULL;<br />

int n = x->dimensions[0];<br />

for (int d = 1; d < x->nd; d++) % NumPy arrays can be multi-dimensional!<br />

n *= x->dimensions[d];<br />

int incx = 1;<br />

}<br />

if (x->descr->type_num == PyArray_DOUBLE)<br />

dscal_(&n, &(alpha.real), DOUBLEP(x), &incx);<br />

else<br />

zscal_(&n, &alpha, (void*)COMPLEXP(x), &incx);<br />

Py_RETURN_NONE;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!