Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
7ddb28ca
Commit
7ddb28ca
authored
Jun 23, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved an example from pure.rst to the examples directory.
parent
084a25f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
17 deletions
+18
-17
docs/examples/tutorial/pure/mymodule.pxd
docs/examples/tutorial/pure/mymodule.pxd
+5
-0
docs/examples/tutorial/pure/mymodule.py
docs/examples/tutorial/pure/mymodule.py
+10
-0
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+3
-17
No files found.
docs/examples/tutorial/pure/mymodule.pxd
0 → 100644
View file @
7ddb28ca
# mymodule.pxd
# declare a C function as "cpdef" to export it to the module
cdef
extern
from
"math.h"
:
cpdef
double
sin
(
double
x
)
docs/examples/tutorial/pure/mymodule.py
0 → 100644
View file @
7ddb28ca
# mymodule.py
import
cython
# override with Python import if not in compiled code
if
not
cython
.
compiled
:
from
math
import
sin
# calls sin() from math.h when compiled with Cython and math.sin() in Python
print
(
sin
(
0
))
docs/src/tutorial/pure.rst
View file @
7ddb28ca
...
@@ -299,25 +299,11 @@ Calling C functions
...
@@ -299,25 +299,11 @@ Calling C functions
Normally, it isn't possible to call C functions in pure Python mode as there
Normally, it isn't possible to call C functions in pure Python mode as there
is no general way to support it in normal (uncompiled) Python. However, in
is no general way to support it in normal (uncompiled) Python. However, in
cases where an equivalent Python function exists, this can be achieved by
cases where an equivalent Python function exists, this can be achieved by
combining C function coercion with a conditional import as follows:
:
combining C function coercion with a conditional import as follows:
# in mymodule.pxd:
.. literalinclude:: ../../examples/tutorial/pure/mymodule.pxd
# declare a C function as "cpdef" to export it to the module
.. literalinclude:: ../../examples/tutorial/pure/mymodule.py
cdef extern from "math.h":
cpdef double sin(double x)
# in mymodule.py:
import cython
# override with Python import if not in compiled code
if not cython.compiled:
from math import sin
# calls sin() from math.h when compiled with Cython and math.sin() in Python
print(sin(0))
Note that the "sin" function will show up in the module namespace of "mymodule"
Note that the "sin" function will show up in the module namespace of "mymodule"
here (i.e. there will be a ``mymodule.sin()`` function). You can mark it as an
here (i.e. there will be a ``mymodule.sin()`` function). You can mark it as an
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment