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
559449a2
Commit
559449a2
authored
Apr 11, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update docs on optimised builtins
--HG-- extra : rebase_source : fb47cc7e0154abb172016f1945dad2968b3f2a3e
parent
cb945502
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
40 deletions
+60
-40
docs/src/reference/language_basics.rst
docs/src/reference/language_basics.rst
+30
-16
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+30
-24
No files found.
docs/src/reference/language_basics.rst
View file @
559449a2
...
@@ -572,43 +572,52 @@ Function Pointers
...
@@ -572,43 +572,52 @@ Function Pointers
* Functions declared in a ``struct`` are automatically converted to function pointers.
* Functions declared in a ``struct`` are automatically converted to function pointers.
* see **using exceptions with function pointers**
* see **using exceptions with function pointers**
Python Built-ins
Python Built-ins
================
================
The following are provided:
Cython compiles calls to most built-in functions into direct calls to
the corresponding Python/C API routines, making them particularly fast.
.. todo:: incomplete
Only direct function calls using these names are optimised. If you do
something else with one of these names that assumes it's a Python object,
such as assign it to a Python variable, and later call it, the call will
be made as a Python function call.
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| Function and arguments | Return type | Python/C API Equivalent |
| Function and arguments | Return type | Python/C API Equivalent |
+==============================+=============+============================+
+==============================+=============+============================+
| abs(obj) | object | PyNumber_Absolute |
| abs(obj) | object, | PyNumber_Absolute, fabs, |
| | double, ... | fabsf, ... |
+------------------------------+-------------+----------------------------+
| callable(obj) | bint | PyObject_Callable |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
|
bool(obj) | object | Py_True, Py_False
|
|
delattr(obj, name) | None | PyObject_DelAttr
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
|
chr(obj) | object | char
|
|
exec(code, [glob, [loc]]) | object | -
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| d
elattr(obj, name) | int | PyObject_DelAttr
|
| d
ir(obj) | list | PyObject_Dir
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| dir(obj) | object | PyObject_Dir |
| divmod(a, b) | tuple | PyNumber_Divmod |
| getattr(obj, name) (Note 1) | | |
| getattr3(obj, name, default) | | |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| hasattr(obj, name) | int | PyObject_HasAttr |
| getattr(obj, name, [default])| object | PyObject_GetAttr |
| (Note 1) | | |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| has
h(obj) | int | PyObject_Hash
|
| has
attr(obj, name) | bint | PyObject_HasAttr
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
|
intern(obj) | object | PyObject_InternFromString
|
|
hash(obj) | int / long | PyObject_Hash
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| i
sinstance(obj, type) | int | PyObject_IsInstance
|
| i
ntern(obj) | object | Py*_InternFromString
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| is
subclass(obj, type) | int | PyObject_IsSubclass
|
| is
instance(obj, type) | bint | PyObject_IsInstance
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| iter(obj) | object | PyObject_GetIter |
| issubclass(obj, type) | bint | PyObject_IsSubclass |
+------------------------------+-------------+----------------------------+
| iter(obj, [sentinel]) | object | PyObject_GetIter |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| len(obj) | Py_ssize_t | PyObject_Length |
| len(obj) | Py_ssize_t | PyObject_Length |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| pow(x, y,
z) (Note 2)
| object | PyNumber_Power |
| pow(x, y,
[z])
| object | PyNumber_Power |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| reload(obj) | object | PyImport_ReloadModule |
| reload(obj) | object | PyImport_ReloadModule |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
...
@@ -617,6 +626,11 @@ The following are provided:
...
@@ -617,6 +626,11 @@ The following are provided:
| setattr(obj, name) | void | PyObject_SetAttr |
| setattr(obj, name) | void | PyObject_SetAttr |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
Note 1: Pyrex originally provided a function :func:`getattr3(obj, name, default)`
corresponding to the three-argument form of the Python builtin :func:`getattr()`.
Cython still supports this function, but the usage is deprecated in favour of
the normal builtin, which Cython can optimise in both forms.
============================
============================
Error and Exception Handling
Error and Exception Handling
...
...
docs/src/userguide/language_basics.rst
View file @
559449a2
...
@@ -387,35 +387,48 @@ Python variable residing in the scope where it is assigned.
...
@@ -387,35 +387,48 @@ Python variable residing in the scope where it is assigned.
Built-in Functions
Built-in Functions
------------------
------------------
Cython compiles calls to
the following
built-in functions into direct calls to
Cython compiles calls to
most
built-in functions into direct calls to
the corresponding Python/C API routines, making them particularly fast.
the corresponding Python/C API routines, making them particularly fast.
Only direct function calls using these names are optimised. If you do
something else with one of these names that assumes it's a Python object,
such as assign it to a Python variable, and later call it, the call will
be made as a Python function call.
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| Function and arguments | Return type | Python/C API Equivalent |
| Function and arguments | Return type | Python/C API Equivalent |
+==============================+=============+============================+
+==============================+=============+============================+
| abs(obj) | object | PyNumber_Absolute |
| abs(obj) | object, | PyNumber_Absolute, fabs, |
| | double, ... | fabsf, ... |
+------------------------------+-------------+----------------------------+
| callable(obj) | bint | PyObject_Callable |
+------------------------------+-------------+----------------------------+
| delattr(obj, name) | None | PyObject_DelAttr |
+------------------------------+-------------+----------------------------+
| exec(code, [glob, [loc]]) | object | - |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| d
elattr(obj, name) | int | PyObject_DelAttr
|
| d
ir(obj) | list | PyObject_Dir
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| dir(obj) | object | PyObject_Dir |
| divmod(a, b) | tuple | PyNumber_Divmod |
| getattr(obj, name) (Note 1) | | |
| getattr3(obj, name, default) | | |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| hasattr(obj, name) | int | PyObject_HasAttr |
| getattr(obj, name, [default])| object | PyObject_GetAttr |
| (Note 1) | | |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| has
h(obj) | int | PyObject_Hash
|
| has
attr(obj, name) | bint | PyObject_HasAttr
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
|
intern(obj) | object | PyObject_InternFromString
|
|
hash(obj) | int / long | PyObject_Hash
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| i
sinstance(obj, type) | int | PyObject_IsInstance
|
| i
ntern(obj) | object | Py*_InternFromString
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| is
subclass(obj, type) | int | PyObject_IsSubclass
|
| is
instance(obj, type) | bint | PyObject_IsInstance
|
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| iter(obj) | object | PyObject_GetIter |
| issubclass(obj, type) | bint | PyObject_IsSubclass |
+------------------------------+-------------+----------------------------+
| iter(obj, [sentinel]) | object | PyObject_GetIter |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| len(obj) | Py_ssize_t | PyObject_Length |
| len(obj) | Py_ssize_t | PyObject_Length |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| pow(x, y,
z) (Note 2)
| object | PyNumber_Power |
| pow(x, y,
[z])
| object | PyNumber_Power |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
| reload(obj) | object | PyImport_ReloadModule |
| reload(obj) | object | PyImport_ReloadModule |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
...
@@ -424,17 +437,10 @@ the corresponding Python/C API routines, making them particularly fast.
...
@@ -424,17 +437,10 @@ the corresponding Python/C API routines, making them particularly fast.
| setattr(obj, name) | void | PyObject_SetAttr |
| setattr(obj, name) | void | PyObject_SetAttr |
+------------------------------+-------------+----------------------------+
+------------------------------+-------------+----------------------------+
Note 1: There are two different functions corresponding to the Python
Note 1: Pyrex originally provided a function :func:`getattr3(obj, name, default)`
:func:`getattr` depending on whether a third argument is used. In a Python
corresponding to the three-argument form of the Python builtin :func:`getattr()`.
context, they both evaluate to the Python :func:`getattr` function.
Cython still supports this function, but the usage is deprecated in favour of
the normal builtin, which Cython can optimise in both forms.
Note 2: Only the three-argument form of :func:`pow` is supported. Use the
``**`` operator otherwise.
Only direct function calls using these names are optimised. If you do
something else with one of these names that assumes it's a Python object, such
as assign it to a Python variable, and later call it, the call will be made as
a Python function call.
Operator Precedence
Operator Precedence
...
...
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