現在、私はpythonコードのパフォーマンスボトルネックをcに移動して、結果の効果を調べています。このコードはシミュレーションを実行し、結果をctypes経由でPythonに報告します。しかし、タイプが正しく一致するようにするのに問題があります。ctypesを使用して整数配列を置換します
私はこの特定の問題を解決しようとしていますが、ドキュメンテーションと手順が少し薄いように見えるため、ctypesの使用に関するより一般的なアドバイスを探しています。
I次のCの関数があります。extern "C" {
void f(int* array, int arraylen) {
for(int i = 0; i < arraylen; i++) {
array[i] = g() // mutate the value array[i];
}
}
}
とPythonに次のコードを:
Traceback (most recent call last):
File "particle.py", line 9, in <module>
_f(buffer, seqlen)
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_int instance instead of _ctypes.ArrayType
おかげで、私は省略のです私の配列のインスタンス化の括弧は型の不一致を引き起こしました。 –