I'm using ctypes and I'm passing a ndarray to a c-function. It gives me a odd output behavior. Heres some code:
C-Function:
int foo(int * foo,int N){
for(int i=0;i<N;i++){
cout << "i " << i << " "<< foo[i] << endl;
}
return 0;
}
Python:
from ctypes import *
import numpy as np
bar = cdll.LoadLibrary(".../libtest.so")
N = c_int(10)
check = np.ones(10, dtype=int)
print check
bar.foo(c_int(check.ctypes.data),N)
Output:
[1 1 1 1 1 1 1 1 1 1]
i:0 out:1
i:1 out:0
i:2 out:1
i:3 out:0
i:4 out:1
i:5 out:0
i:6 out:1
i:7 out:0
i:8 out:1
i:9 out:0
Should be all ones right? :)
I' compiling with
g++ -g -c -fPIC -O0 pythagoras.cpp
g++ -shared -Wl,-soname=libtest.so -o libtest.so pythagoras.o
Anyone any ideas? I'm searching the failure now for at least 1hr and I'm having no idea what the solution is(probably something stupid)
Thanks in advance!