Dalek - 5 months ago 29

C Question

I am struggling to use the concept of pointer in my

`cython`

`func`

`from cpython cimport array`

import cython

import ctypes

cimport numpy as np

ctypedef void (*myFuncDef)(double *, double *)

from cython.parallel import prange

cdef void func(int* x, double* hx, void(*func)(double*, double*), int n):

def int i

for i from 0 <= i < n:

func[0](&x[i], &hx[i])

return

cpdef void Lognormal(double* u,

double* yu):

#evaluate log of normal distribution

yu=-u*u*0.5

return

def foo(np.ndarray[ndim=1, dtype=np.float64_t] x,

np.ndarray[ndim=1, dtype=np.float64_t] hx,

myFuncDef distribution, int k):

cdef np.ndarray[ndim=1, dtype=np.float64_t] sp

cdef int num=len(x)

cdef int j

for j from 0 <= j <k:

func(&x[0],&hx[0],&distribution, num)

sp[j]=hx[0]

return sp

So I would like to used the

`Lognormal`

`foo`

`Cannot assign type 'myFuncDef *' to 'void (*)(double *, double *)'`

I will appreciate for any suggestion to fix this bug.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You have one too many layers of pointer (the standard issue raised to argue against `typedef`

s for pointers). Just drop the `&`

from `&distribution`

; it's already the function pointer you want.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**