Browse Source

Cython

pull/61/head
Jure Šorn 4 years ago
parent
commit
56d36433b4
2 changed files with 17 additions and 22 deletions
  1. 17
      README.md
  2. 22
      index.html

17
README.md

@ -3428,8 +3428,15 @@ Cython
```python
# $ pip3 install cython
import pyximport; pyximport.install()
import <cython_script>
<cython_script>.main()
```
### Definitions
* **All `'cdef'` definitions are optional, but they contribute to the speed-up.**
* **Script needs to be saved with a `'pyx'` extension.**
```python
cdef <type> <var_name> = <el>
cdef <type>[n_elements] <var_name> = [<el_1>, <el_2>, ...]
@ -3446,16 +3453,6 @@ cdef class <class_name>:
```python
cdef enum <enum_name>: <member_name_1>, <member_name_2>, ...
```
* **All `'cdef'` definitions are optional, but they contribute to the speed-up.**
* **Script needs to be saved with a `'pyx'` extension.**
#### Running Cython code:
```python
#!/usr/bin/env python3
import pyximport; pyximport.install()
import <pyx_script_name>
<pyx_script_name>.main()
```
Basic Script Template

22
index.html

@ -2912,13 +2912,21 @@ plotly.express.line(df, x=<span class="hljs-string">'Date'</span>, y=<span class
<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>
<span class="hljs-keyword">import</span> pyximport; pyximport.install()
<span class="hljs-keyword">import</span> &lt;cython_script&gt;
&lt;cython_script&gt;.main()
</code></pre></div>
<pre><code class="python language-python hljs">cdef &lt;type&gt; &lt;var_name&gt; = &lt;el&gt;
<div><h3 id="definitions">Definitions</h3><ul>
<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>
<li><strong>Script needs to be saved with a <code class="python hljs"><span class="hljs-string">'pyx'</span></code> extension.</strong></li>
</ul><pre><code class="python language-python hljs">cdef &lt;type&gt; &lt;var_name&gt; = &lt;el&gt;
cdef &lt;type&gt;[n_elements] &lt;var_name&gt; = [&lt;el_1&gt;, &lt;el_2&gt;, ...]
cdef &lt;type/void&gt; &lt;func_name&gt;(&lt;type&gt; &lt;arg_name_1&gt;, ...):
</code></pre>
</code></pre></div>
<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>
cdef public &lt;type&gt; &lt;attr_name&gt;
<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>
@ -2926,16 +2934,6 @@ cdef &lt;type/void&gt; &lt;func_name&gt;(&lt;type&gt; &lt;arg_name_1&gt;, ...):
</code></pre>
<pre><code class="python language-python hljs">cdef enum &lt;enum_name&gt;: &lt;member_name_1&gt;, &lt;member_name_2&gt;, ...
</code></pre>
<ul>
<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>
<li><strong>Script needs to be saved with a <code class="python hljs"><span class="hljs-string">'pyx'</span></code> extension.</strong></li>
</ul>
<div><h4 id="runningcythoncode">Running Cython code:</h4><pre><code class="python language-python hljs"><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-keyword">import</span> pyximport; pyximport.install()
<span class="hljs-keyword">import</span> &lt;pyx_script_name&gt;
&lt;pyx_script_name&gt;.main()
</code></pre></div>
<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>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># Usage: .py</span>

Loading…
Cancel
Save