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
Boxiang Sun
cython
Commits
83b89d18
Commit
83b89d18
authored
Apr 02, 2011
by
Francesc Alted
Committed by
Dag Sverre Seljebotn
Apr 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some final cleanup for numpy tutorial
parent
7548da6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
docs/src/tutorial/index.rst
docs/src/tutorial/index.rst
+1
-1
docs/src/tutorial/numpy.rst
docs/src/tutorial/numpy.rst
+10
-9
No files found.
docs/src/tutorial/index.rst
View file @
83b89d18
...
...
@@ -10,9 +10,9 @@ Tutorials
pxd_files
caveats
profiling_tutorial
numpy
strings
pure
numpy
readings
related_work
appendix
...
...
docs/src/tutorial/numpy.rst
View file @
83b89d18
Using Cython with NumPy
=======================
Working with NumPy
=======================
Cython has support for fast access to NumPy arrays. Let's see how this
works with a simple example.
You can use NumPy from Cython exactly the same as in regular Python, but by
doing so you are loosing potentially high speedups because Cython has support
for fast access to NumPy arrays. Let's see how this works with a simple
example.
The code below does 2D discrete convolution of an image with a filter (and I'm
sure you can do better!, let it serve for demonstration purposes). It is both
valid Python and valid Cython code. I'll refer to it as both
:file:`convolve_py.py` for the Python version and :file:`convolve1.pyx` for
the
Cython version -- Cython uses ".pyx" as its file suffix.
:file:`convolve_py.py` for the Python version and :file:`convolve1.pyx` for
the
Cython version -- Cython uses ".pyx" as its file suffix.
.. code-block:: python
...
...
@@ -94,7 +97,7 @@ Adding types
=============
To add types we use custom Cython syntax, so we are now breaking Python source
compatibility.
Here's :file:`convolve2.pyx`. *Read the comments!*
::
compatibility.
Consider this code (*read the comments!*)
::
from __future__ import division
import numpy as np
...
...
@@ -187,9 +190,7 @@ We do this with a special "buffer" syntax which must be told the datatype
(first argument) and number of dimensions ("ndim" keyword-only argument, if
not provided then one-dimensional is assumed).
More information on this syntax [:enhancements/buffer:can be found here].
Showing the changes needed to produce :file:`convolve3.pyx` only::
These are the needed changes::
...
def naive_convolve(np.ndarray[DTYPE_t, ndim=2] f, np.ndarray[DTYPE_t, ndim=2] g):
...
...
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