documentation
.HELP!
Cython 0.19.1 Documentation
Interfacing with Other Code
Cython 0.19.1
previous page
next page
Navigation
next
previous
|
Cython 0.19.1 documentation
»
Reference Guide
»
Interfacing with Other Code
C
C++
Fortran
NumPy
Navigation
next
previous
|
Cython 0.19.1 documentation
»
Reference Guide
»
previous page
start
next page
Menu
Homepage
Table of contents
Cython 0.19.1 documentation
Getting Started
Cython - an overview
Installing Cython
Building Cython code
Building a Cython module using distutils
Faster code via static typing
Typing Variables
Typing Functions
Determining where to add types
Tutorials
Calling C functions
Dynamic linking
External declarations
Naming parameters
Using C libraries
Defining external declarations
Writing a wrapper class
Memory management
Compiling and linking
Mapping functionality
Handling errors
Testing the result
Callbacks
Extension types (aka. cdef classes)
pxd files
Caveats
Profiling
Cython Profiling Basics
Enabling profiling for a complete source file
Disabling profiling function wise
Profiling Tutorial
Unicode and passing strings
General notes about C strings
Passing byte strings
Dealing with "const"
Decoding bytes to text
Encoding text to bytes
C++ strings
Auto encoding and decoding
Source code encoding
Single bytes and characters
Narrow Unicode builds
Iteration
Windows and wide character APIs
Pure Python Mode
Magic Attributes
Augmenting .pxd
Types
Extension types and cdef functions
Working with NumPy
Adding types
Efficient indexing
Tuning indexing further
More generic code
Further reading
Related work
Appendix: Installing MinGW on Windows
Users Guide
Overview
About Cython
Future Plans
Basic Tutorial
The Basics of Cython
Cython Hello World
pyximport: Cython Compilation the Easy Way
Fibonacci Fun
Primes
Language Details
Language Basics
C variable and type definitions
Grouping multiple C declarations
Python functions vs. C functions
Python objects as parameters and return values
Error return values
Checking return values of non-Cython functions
Automatic type conversions
Caveats when using a Python string in a C context
Statements and expressions
Differences between C and Cython expressions
Scope rules
Built-in Functions
Operator Precedence
Integer for-loops
The include statement
Conditional Compilation
Compile-Time Definitions
Conditional Statements
Extension Types
Introduction
Attributes
Type declarations
Type Testing and Casting
Extension types and None
Special methods
Properties
Subclassing
C methods
Forward-declaring extension types
Fast instantiation
Making extension types weak-referenceable
Public and external extension types
External extension types
Name specification clause
Implicit importing
Type names vs. constructor names
Public extension types
Special Methods of Extension Types
Declaration
Docstrings
Initialisation methods: __cinit__() and __init__()
Finalization method: __dealloc__()
Arithmetic methods
Rich comparisons
The __next__() method
Special Method Table
General
Arithmetic operators
Numeric conversions
In-place arithmetic operators
Sequences and mappings
Iterators
Buffer interface [PEP 3118] (no Python equivalents - see note 1)
Buffer interface [legacy] (no Python equivalents - see note 1)
Descriptor objects (see note 2)
Sharing Declarations Between Cython Modules
Definition and Implementation files
What a Definition File contains
What an Implementation File contains
The cimport statement
Search paths for definition files
Using cimport to resolve naming conflicts
Sharing C Functions
Sharing Extension Types
Interfacing with External C Code
External declarations
Referencing C header files
Styles of struct, union and enum declaration
Accessing Python/C API routines
Special Types
Windows Calling Conventions
Resolving naming conflicts - C name specifications
Using Cython Declarations from C
Public Declarations
C API Declarations
Multiple public and API declarations
Acquiring and Releasing the GIL
Releasing the GIL
Acquiring the GIL
Declaring a function as callable without the GIL
Source Files and Compilation
Basic setup.py
Cython Files Depending on C Files
Multiple Cython Files in a Package
Distributing Cython modules
Pyximport
Dependency Handling
Limitations
For further thought and discussion
Early Binding for Speed
Using C++ in Cython
Overview
What's new in Cython v0.13 about C++
Procedure Overview
A simple Tutorial
An example C++ API
Specify C++ language in setup.py
Declaring a C++ class interface
Declare class with cdef cppclass
Add public attributes
Declare a var with the wrapped C++ class
Create Cython wrapper class
Advanced C++ features
Overloading
Overloading operators
Nested class declarations
C++ operators not compatible with Python syntax
Templates
Standard library
Exceptions
Static member method
Caveats and Limitations
Access to C-only functions
Declaring/Using References
C++ left-values
Fused Types (Templates)
Quickstart
Declaring Fused Types
Using Fused Types
Fused types and arrays
Selecting Specializations
Indexing
Calling
Built-in Fused Types
Casting Fused Functions
Type Checking Specializations
__signatures__
Porting Cython code to PyPy
Reference counts
Object lifetime
Borrowed references and data pointers
Builtin types, slots and fields
Efficiency
Known problems
Bugs and crashes
Limitations
Differences between Cython and Pyrex
Python 3 Support
List/Set/Dict Comprehensions
Keyword-only arguments
Conditional expressions "x if b else y" (Python 2.5)
cdef inline
Assignment on declaration (e.g. "cdef int spam = 5")
'by' expression in for loop (e.g. "for i from 0 <= i < 10 by 2")
Boolean int type (e.g. it acts like a c int, but coerces to/from python as a boolean)
Executable class bodies
cpdef functions
Automatic range conversion
More friendly type casting
Optional arguments in cdef/cpdef functions
Function pointers in structs
C++ Exception handling
Synonyms
Source code encoding
Automatic typecheck
From __future__ directives
Pure Python mode
Typed Memoryviews
Quickstart
Using memoryviews
Indexing and Slicing
Copying
Transposing
Newaxis
Comparison to the old buffer support
Python buffer support
Memory layout
Background
Brief recap on C, Fortran and strided memory layouts
Default behavior for memoryview layouts
C and Fortran contiguous memoryviews
C and Fortran contiguous copies
Specifying more general memory layouts
Memoryviews and the GIL
Memoryview Objects and Cython Arrays
Cython arrays
CPython array module
Coercion to NumPy
None Slices
Using Parallelism
Compiling
Breaking out of loops
Using OpenMP Functions
Debugging your Cython program
Running the Debugger
Using the Debugger
Convenience functions
Configuring the Debugger
Indices and tables
Reference Guide
Compilation
Compiling from the command line
Compiling with distutils
Compiling with pyximport
Compiling with cython.inline
Compiling with Sage
Compiler directives
How to set directives
Globally
Locally
Language Basics
Cython File Types
Implementation File
What can it contain?
What can't it contain?
Definition File
What can it contain?
What can't it contain?
What else?
cimport
compilation order
Include File
What can it contain?
How do I use it?
Declaring Data Types
The cdef Statement
Grouping cdef Declarations
Parameters
Optional Arguments
Keyword-only Arguments
Automatic Type Conversion
Type Casting
Type Checking
Python Objects
Statements and Expressions
Differences Between Cython and C
Scope Rules
Built-in Constants
Operator Precedence
For-loops
Functions and Methods
Callable from Python
Callable from C
Callable from both Python and C
Overriding
Function Pointers
Python Built-ins
Error and Exception Handling
Checking return values for non-Cython functions..
Conditional Compilation
Compile-Time Definitions
Conditional Statements
Extension Types
Attributes
Methods
Properties
Special Methods
Declaration
Docstrings
Initialization: __cinit__() and __init__()
Finalization: __dealloc__()
Arithmetic Methods
Rich Comparisons
The __next__() Method
Subclassing
Forward Declarations
Extension Types and None
Weak Referencing
External and Public Types
Public
External
Name Specification Clause
Type Names vs. Constructor Names
Interfacing with Other Code
C
C++
Fortran
NumPy
Special Mention
Limitations
Compiler Directives
Indices and tables
Special Methods Table
General
Arithmetic operators
Numeric conversions
In-place arithmetic operators
Sequences and mappings
Iterators
Buffer interface
Descriptor objects
Get in touch
Submit feedback about this site to:
[email protected]