質問編集履歴
4
cython側```追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
### ソースコード
|
18
18
|
# Cyhonソースコード(module_cython.pyx)
|
19
|
+
```cython
|
19
20
|
import numpy as np
|
20
21
|
cimport numpy as cnp
|
21
22
|
cimport cython
|
@@ -27,6 +28,7 @@
|
|
27
28
|
data = np.loadtxt(filepath, dtype = "unicode", delimiter = ' ') #csv(TSV)ファイルを読み込み
|
28
29
|
|
29
30
|
return data
|
31
|
+
```
|
30
32
|
|
31
33
|
# 呼び出し側のPythonソースコード(main.py)
|
32
34
|
```python
|
3
誤記修正:'''→```
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,13 +29,13 @@
|
|
29
29
|
return data
|
30
30
|
|
31
31
|
# 呼び出し側のPythonソースコード(main.py)
|
32
|
-
|
32
|
+
```python
|
33
33
|
from module_cython import fileread_cython
|
34
34
|
|
35
35
|
filepath = "C:/test/test.csv"
|
36
36
|
|
37
37
|
print(fileread_cython(filepath))
|
38
|
-
|
38
|
+
```
|
39
39
|
|
40
40
|
### 試したこと
|
41
41
|
上のソースコードで①、②をコメントアウトすれば動作しますので、
|
2
Cyhonソースコードのreturnとpath->filepathに間違いがありましたので修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,10 +22,11 @@
|
|
22
22
|
|
23
23
|
ctypedef cnp.unicode DTYPE_U_t #Numpyのデータタイプを宣言 --①
|
24
24
|
|
25
|
-
def fileread_cython(path):
|
25
|
+
def fileread_cython(filepath):
|
26
26
|
cdef cnp.ndarray[DTYPE_U_t, ndim=2] data #deta変数を型宣言 --②
|
27
27
|
data = np.loadtxt(filepath, dtype = "unicode", delimiter = ' ') #csv(TSV)ファイルを読み込み
|
28
28
|
|
29
|
+
return data
|
29
30
|
|
30
31
|
# 呼び出し側のPythonソースコード(main.py)
|
31
32
|
'''python
|
1
後半(pythonソースコード部分)をコメントに変更しました。ご指摘ありがとうございます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
### 発生している問題・エラーメッセージ
|
11
11
|
Cdefの宣言文を追加すると実行時に以下のエラーメッセージが発生しました。
|
12
|
-
(コンパイルを行い、.p
|
12
|
+
(コンパイルを行い、.c、.pydファイルまではできています)
|
13
13
|
|
14
14
|
エラーメッセージ
|
15
15
|
Does not understand character buffer dtype format string ('w')
|
@@ -28,11 +28,13 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
# 呼び出し側のPythonソースコード(main.py)
|
31
|
+
'''python
|
31
32
|
from module_cython import fileread_cython
|
32
33
|
|
33
34
|
filepath = "C:/test/test.csv"
|
34
35
|
|
35
36
|
print(fileread_cython(filepath))
|
37
|
+
'''
|
36
38
|
|
37
39
|
### 試したこと
|
38
40
|
上のソースコードで①、②をコメントアウトすれば動作しますので、
|