⇤ ← Revision 1 as of 2020-03-20 16:13:30
Size: 128
Comment:
|
Size: 974
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 6: | Line 6: |
=== Cythonのコードをひとつのファイルで完結させる === Cythonを使って高速化したはいいけど、元々ひとつのコードだったものが複数のファイルになってしまうのは嫌だ。という場合の小技。 コードのファイル名を cython_test.pyx とする。 最後に {{{#!python if __name__ == '__main__': import cython_test cython_test.main() }}} と書いておけば、コンパイルの時は読まれず、実行した時はmain関数が走る。このコードひとつをcythonizeしてからpythonに投げればおk {{{ $ cythonize -a -i cython_test.pyx Compiling /gpfs/home/(カレントディレクトリ)/cython_test.pyx because it changed. [1/1] Cythonizing /gpfs/(カレントディレクトリ)/cython_test.pyx $ python cython_test.pyx }}} |
高速化の小技
Cython
Cythonのコードをひとつのファイルで完結させる
Cythonを使って高速化したはいいけど、元々ひとつのコードだったものが複数のファイルになってしまうのは嫌だ。という場合の小技。
コードのファイル名を cython_test.pyx とする。 最後に
と書いておけば、コンパイルの時は読まれず、実行した時はmain関数が走る。このコードひとつをcythonizeしてからpythonに投げればおk
$ cythonize -a -i cython_test.pyx Compiling /gpfs/home/(カレントディレクトリ)/cython_test.pyx because it changed. [1/1] Cythonizing /gpfs/(カレントディレクトリ)/cython_test.pyx $ python cython_test.pyx