소스 검색

Complex algebra works now! Very nice

master
Pete Shadbolt 10 년 전
부모
커밋
b21edae26f
3개의 변경된 파일19개의 추가작업 그리고 32개의 파일을 삭제
  1. +6
    -4
      run-tests.py
  2. +0
    -5
      run-tests.sh
  3. +13
    -23
      src/permanent.c

+ 6
- 4
run-tests.py 파일 보기

@@ -4,8 +4,10 @@ import multiprocessing as mp
import numpy as np
import lib

dimension=8
real=np.random.uniform(0,1,(dimension, dimension))
imag=np.random.uniform(0,1,(dimension, dimension))
submatrix=real+1j*imag
#dimension=8
#real=np.random.uniform(0,1,(dimension, dimension))
#imag=np.random.uniform(0,1,(dimension, dimension))
#submatrix=real+1j*imag

submatrix=np.array([[69+420j]], dtype=np.complex128)
print "OUTPUT: ", lib.permanent(submatrix)

+ 0
- 5
run-tests.sh 파일 보기

@@ -1,5 +0,0 @@
#!/bin/bash

#rm lib/*.so
python ./setup.py build_ext --inplace &&
python ./run-tests.py

+ 13
- 23
src/permanent.c 파일 보기

@@ -24,25 +24,11 @@ PyMODINIT_FUNC initpermanent(void) {
/*****************************************************************************
* Array access macros. *
*****************************************************************************/
#define m(x0) (*(npy_float64*)((PyArray_DATA(py_m) + \
(x0) * PyArray_STRIDES(py_m)[0])))
#define m_shape(i) (py_m->dimensions[(i)])

#define r(x0, x1) (*(npy_float64*)((PyArray_DATA(py_r) + \
(x0) * PyArray_STRIDES(py_r)[0] + \
(x1) * PyArray_STRIDES(py_r)[1])))
#define r_shape(i) (py_r->dimensions[(i)])

#define v(x0, x1) (*(npy_float64*)((PyArray_DATA(py_v) + \
(x0) * PyArray_STRIDES(py_v)[0] + \
(x1) * PyArray_STRIDES(py_v)[1])))
#define v_shape(i) (py_v->dimensions[(i)])

#define F(x0, x1) (*(npy_float64*)((PyArray_DATA(py_F) + \
(x0) * PyArray_STRIDES(py_F)[0] + \
(x1) * PyArray_STRIDES(py_F)[1])))
#define F_shape(i) (py_F->dimensions[(i)])

static PyObject *permanent(PyObject *self, PyObject *args) {
// Parse input
PyArrayObject *submatrix;
@@ -50,20 +36,24 @@ static PyObject *permanent(PyObject *self, PyObject *args) {
return NULL;
}

// Declare variables.
/*npy_int64 d, i, j;*/
// Testing algebra
npy_complex128 a;

/*a.real=1; a.imag=1;*/
/*b.real=1; b.imag=1;*/

/*a.real=a.real+b.real;*/
/*a.imag=a.imag+b.imag;*/

Py_complex a;
Py_complex b;
// Let's see if we can add to a number from the numpy array
int xpos=0; int ypos=0;
a=(*(npy_complex128*)((PyArray_DATA(submatrix) + \
(xpos) * PyArray_STRIDES(submatrix)[0] + \
(ypos) * PyArray_STRIDES(submatrix)[1])));

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
// Convert to a python complex number and return
PyObject *output=PyComplex_FromDoubles(a.real,a.imag);
return output;



불러오는 중...
취소
저장