From b94619067096e2599646c9361b0e81ea546c9dcb Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Fri, 24 Oct 2014 07:12:01 +1100 Subject: [PATCH] Messing around with complex algebra --- makefile | 21 +++++++++++++++++++++ src/permanent.c | 32 ++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..634105c --- /dev/null +++ b/makefile @@ -0,0 +1,21 @@ +srcdir = src +objdir = ./ + +target = permanent.so +setup = setup.py + +default : $(target) test + +# Compile +$(target): $(srcdir)/permanent.c + python $(setup) build_ext --inplace + +test : + python ./run-tests.py + +clean : + @ rm permanent.so + @ rm -rf build + +tar : + @ tar czf permanent.tar.gz $(srcdir) $(utils) diff --git a/src/permanent.c b/src/permanent.c index 95bca98..115621e 100644 --- a/src/permanent.c +++ b/src/permanent.c @@ -1,5 +1,6 @@ /* Computes the permanent, given a numpy array */ +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include #include #include @@ -23,7 +24,6 @@ PyMODINIT_FUNC initpermanent(void) { /***************************************************************************** * Array access macros. * *****************************************************************************/ -#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define m(x0) (*(npy_float64*)((PyArray_DATA(py_m) + \ (x0) * PyArray_STRIDES(py_m)[0]))) #define m_shape(i) (py_m->dimensions[(i)]) @@ -44,25 +44,37 @@ PyMODINIT_FUNC initpermanent(void) { #define F_shape(i) (py_F->dimensions[(i)]) static PyObject *permanent(PyObject *self, PyObject *args) { - // Declare variables. - npy_int64 d, i, j; - double complex sum; + // Parse input PyArrayObject *submatrix; - - // Parse variables. if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &submatrix)) { return NULL; } + // Declare variables. + /*npy_int64 d, i, j;*/ + + + Py_complex a; + Py_complex b; + + a.real=1; a.imag=1; + b.real=1; b.imag=1; + + a.real=a.real+b.real; + a.imag=a.imag+b.imag; + + // Convert to a python complex number + PyObject *output=PyComplex_FromDoubles(a.real,a.imag); + return output; + + /* + // Compute the permanent for(i = 0; i < d; ++i) { for(j = 0; j