Skip to content

Commit 56d3643

Browse files
committed
Cython
1 parent 39bdcd4 commit 56d3643

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,8 +3428,15 @@ Cython
34283428

34293429
```python
34303430
# $ pip3 install cython
3431+
import pyximport; pyximport.install()
3432+
import <cython_script>
3433+
<cython_script>.main()
34313434
```
34323435

3436+
### Definitions
3437+
* **All `'cdef'` definitions are optional, but they contribute to the speed-up.**
3438+
* **Script needs to be saved with a `'pyx'` extension.**
3439+
34333440
```python
34343441
cdef <type> <var_name> = <el>
34353442
cdef <type>[n_elements] <var_name> = [<el_1>, <el_2>, ...]
@@ -3446,16 +3453,6 @@ cdef class <class_name>:
34463453
```python
34473454
cdef enum <enum_name>: <member_name_1>, <member_name_2>, ...
34483455
```
3449-
* **All `'cdef'` definitions are optional, but they contribute to the speed-up.**
3450-
* **Script needs to be saved with a `'pyx'` extension.**
3451-
3452-
#### Running Cython code:
3453-
```python
3454-
#!/usr/bin/env python3
3455-
import pyximport; pyximport.install()
3456-
import <pyx_script_name>
3457-
<pyx_script_name>.main()
3458-
```
34593456

34603457

34613458
Basic Script Template

index.html

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,30 +2912,28 @@
29122912

29132913

29142914
<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> &lt;cython_script&gt;
2917+
&lt;cython_script&gt;.main()
29152918
</code></pre></div>
29162919

29172920

2918-
<pre><code class="python language-python hljs">cdef &lt;type&gt; &lt;var_name&gt; = &lt;el&gt;
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 &lt;type&gt; &lt;var_name&gt; = &lt;el&gt;
29192925
cdef &lt;type&gt;[n_elements] &lt;var_name&gt; = [&lt;el_1&gt;, &lt;el_2&gt;, ...]
29202926
cdef &lt;type/void&gt; &lt;func_name&gt;(&lt;type&gt; &lt;arg_name_1&gt;, ...):
2921-
</code></pre>
2927+
</code></pre></div>
2928+
2929+
29222930
<pre><code class="python language-python hljs">cdef <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">class_name</span>&gt;:</span>
29232931
cdef public &lt;type&gt; &lt;attr_name&gt;
29242932
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, &lt;type&gt; &lt;arg_name&gt;)</span>:</span>
29252933
self.&lt;attr_name&gt; = &lt;arg_name&gt;
29262934
</code></pre>
29272935
<pre><code class="python language-python hljs">cdef enum &lt;enum_name&gt;: &lt;member_name_1&gt;, &lt;member_name_2&gt;, ...
29282936
</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> &lt;pyx_script_name&gt;
2936-
&lt;pyx_script_name&gt;.main()
2937-
</code></pre></div>
2938-
29392937
<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>
29402938
<span class="hljs-comment">#</span>
29412939
<span class="hljs-comment"># Usage: .py</span>

0 commit comments

Comments
 (0)