v[i] -= 2*d[j]*M[j][i]
from __future__ import division
import numpy as np
cimport numpy as np
DTYPE_int = np.int
ctypedef np.int_t DTYPE_int_t
DTYPE_float = np.float64
ctypedef np.float64_t DTYPE_float_t
def permfunc(np.ndarray [DTYPE_float_t, ndim =2] M):
cdef int n = M.shape[0]
cdef np.ndarray[DTYPE_float_t, ndim =1] d = np.ones(n, dtype=DTYPE_float)
cdef int j = 0
cdef int s = 1
cdef np.ndarray [DTYPE_int_t, ndim =1] f = np.arange(n, dtype=DTYPE_int)
cdef np.ndarray [DTYPE_float_t, ndim =1] v = M.sum(axis=0)
cdef DTYPE_float_t p = 1
cdef int i
cdef double prod
for i in range(n):
p *= v[i]
while (j < n-1):
for i in range(n):
v[i] -= 2*d[j]*M[j][i]
d[j] = -d[j]
s = -s
prod = 1
for i in range(n):
prod *= v[i]
p += s*prod
f[0] = 0
f[j] = f[j+1]
f[j+1] = j+1
j = f[0]
return p/2**(n-1)
Am 23.12.2016 um 11:51 schrieb Raphael C <drr...@gmail.com>:I have some code I am trying to make fast using cython. It takes in a 2d numpy array of floating point numbers in a matrix called M. When I run cython -a on it I see that one crucial line is still being interpreted in python. The offending line isv[i] -= 2*d[j]*M[j][i]
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 23 December 2016 at 13:59, Gregor Thalhammer
>> v[i] -= 2*d[j]*M[j][i]
> v[i] -= 2*d[j]*M[j,i]
>
> Does this improve speed?
Amazingly that seems to be the answer!