diff options
author | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-13 14:11:38 +0200 |
---|---|---|
committer | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-13 14:11:38 +0200 |
commit | 0a77e3a93be768c9a50e3469d2dbe5d6652c5686 (patch) | |
tree | 06d55c4d5d66e2fce8baa5b71ca73535cae29cdf /docs/examples/quickstart | |
parent | 5fadf79efd37273873c1be2353969445118ed903 (diff) | |
download | cython-0a77e3a93be768c9a50e3469d2dbe5d6652c5686.tar.gz |
Moved the code snippets from the .rst file to the examples directory. Those code snippets are now tested with the mode "compile".
Diffstat (limited to 'docs/examples/quickstart')
-rw-r--r-- | docs/examples/quickstart/cythonize/cdef_keyword.pyx | 2 | ||||
-rw-r--r-- | docs/examples/quickstart/cythonize/integrate.py | 10 | ||||
-rw-r--r-- | docs/examples/quickstart/cythonize/integrate_cy.pyx | 12 |
3 files changed, 24 insertions, 0 deletions
diff --git a/docs/examples/quickstart/cythonize/cdef_keyword.pyx b/docs/examples/quickstart/cythonize/cdef_keyword.pyx new file mode 100644 index 000000000..16503ee89 --- /dev/null +++ b/docs/examples/quickstart/cythonize/cdef_keyword.pyx @@ -0,0 +1,2 @@ +cdef double f(double x) except? -2:
+ return x ** 2 - x
diff --git a/docs/examples/quickstart/cythonize/integrate.py b/docs/examples/quickstart/cythonize/integrate.py new file mode 100644 index 000000000..8d420b923 --- /dev/null +++ b/docs/examples/quickstart/cythonize/integrate.py @@ -0,0 +1,10 @@ +def f(x):
+ return x ** 2 - x
+
+
+def integrate_f(a, b, N):
+ s = 0
+ dx = (b - a) / N
+ for i in range(N):
+ s += f(a + i * dx)
+ return s * dx
diff --git a/docs/examples/quickstart/cythonize/integrate_cy.pyx b/docs/examples/quickstart/cythonize/integrate_cy.pyx new file mode 100644 index 000000000..0bb0cd548 --- /dev/null +++ b/docs/examples/quickstart/cythonize/integrate_cy.pyx @@ -0,0 +1,12 @@ +def f(double x):
+ return x ** 2 - x
+
+
+def integrate_f(double a, double b, int N):
+ cdef int i
+ cdef double s, dx
+ s = 0
+ dx = (b - a) / N
+ for i in range(N):
+ s += f(a + i * dx)
+ return s * dx
|