|
2912 | 2912 |
|
2913 | 2913 |
|
2914 | 2914 | <div><h2 id="cython"><a href="#cython" name="cython">#</a>Cython</h2><p><strong>Library that compiles Python code into C.</strong></p><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install cython</span>
|
| 2915 | +<span class="hljs-keyword">import</span> pyximport; pyximport.install() |
| 2916 | +<span class="hljs-keyword">import</span> <cython_script> |
| 2917 | +<cython_script>.main() |
2915 | 2918 | </code></pre></div>
|
2916 | 2919 |
|
2917 | 2920 |
|
2918 |
| -<pre><code class="python language-python hljs">cdef <type> <var_name> = <el> |
| 2921 | +<div><h3 id="definitions">Definitions</h3><ul> |
| 2922 | +<li><strong>All <code class="python hljs"><span class="hljs-string">'cdef'</span></code> definitions are optional, but they contribute to the speed-up.</strong></li> |
| 2923 | +<li><strong>Script needs to be saved with a <code class="python hljs"><span class="hljs-string">'pyx'</span></code> extension.</strong></li> |
| 2924 | +</ul><pre><code class="python language-python hljs">cdef <type> <var_name> = <el> |
2919 | 2925 | cdef <type>[n_elements] <var_name> = [<el_1>, <el_2>, ...]
|
2920 | 2926 | cdef <type/void> <func_name>(<type> <arg_name_1>, ...):
|
2921 |
| -</code></pre> |
| 2927 | +</code></pre></div> |
| 2928 | + |
| 2929 | + |
2922 | 2930 | <pre><code class="python language-python hljs">cdef <span class="hljs-class"><span class="hljs-keyword">class</span> <<span class="hljs-title">class_name</span>>:</span>
|
2923 | 2931 | cdef public <type> <attr_name>
|
2924 | 2932 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, <type> <arg_name>)</span>:</span>
|
2925 | 2933 | self.<attr_name> = <arg_name>
|
2926 | 2934 | </code></pre>
|
2927 | 2935 | <pre><code class="python language-python hljs">cdef enum <enum_name>: <member_name_1>, <member_name_2>, ...
|
2928 | 2936 | </code></pre>
|
2929 |
| -<ul> |
2930 |
| -<li><strong>All <code class="python hljs"><span class="hljs-string">'cdef'</span></code> definitions are optional, but they contribute to the speed-up.</strong></li> |
2931 |
| -<li><strong>Script needs to be saved with a <code class="python hljs"><span class="hljs-string">'pyx'</span></code> extension.</strong></li> |
2932 |
| -</ul> |
2933 |
| -<div><h4 id="runningcythoncode">Running Cython code:</h4><pre><code class="python language-python hljs"><span class="hljs-comment">#!/usr/bin/env python3</span> |
2934 |
| -<span class="hljs-keyword">import</span> pyximport; pyximport.install() |
2935 |
| -<span class="hljs-keyword">import</span> <pyx_script_name> |
2936 |
| -<pyx_script_name>.main() |
2937 |
| -</code></pre></div> |
2938 |
| - |
2939 | 2937 | <div><h2 id="basicscripttemplate"><a href="#basicscripttemplate" name="basicscripttemplate">#</a>Basic Script Template</h2><pre><code class="python language-python hljs"><span class="hljs-comment">#!/usr/bin/env python3</span>
|
2940 | 2938 | <span class="hljs-comment">#</span>
|
2941 | 2939 | <span class="hljs-comment"># Usage: .py</span>
|
|
0 commit comments