2016-08-11 2 views
1

Numpy 배열을 C++ 코드로 푸시하려고합니다.Numpy NDPointer : 매개 변수 1을 변환하는 방법을 모릅니다.

는 C++ 기능은 내가 오류 얻을

from numpy import * 
from numpy.ctypeslib import ndpointer 
import ctypes 

lib = ctypes.cdll.LoadLibrary("libesn.so") 

propagate = lib.propagate 
propagate.restype = None 
propagate.argtype = [ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
        ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
        ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
        ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
        ctypes.c_float, ctypes.c_int, ctypes.c_int] 

H = W = U = X = zeros((10, 10)) 
a = 5.0 
propagate(H, W, U, X, a, U.shape[0], X.shape[0]) 

,

Traceback (most recent call last): 
    File "./minimal.py", line 23, in <module> 
    propagate(H, W, U, X, a, U.shape[0], X.shape[0]) 
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1 

가 어떻게이 문제를 해결 않습니다

extern "C" 
void propagate(float * __restrict__ H, const float * __restrict__ W, 
       const float * __restrict__ U, const float * __restrict__ x, 
       float a, int h_len, int samples); 

내 파이썬 코드가있다?

답변

0

바보 같은 오타가 propagate.argtypes이어야합니다. 이로써 StackOverflow에 대한 답변이 이미있는 다른 오류로 이어지는 신비한 오류가 수정되었습니다.

propagate = lib.propagate 
propagate.restype = None 
propagate.argtypes = [ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
         ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
         ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
         ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"), 
         ctypes.c_float, ctypes.c_int, ctypes.c_int] 
관련 문제