Commit ea65eed8 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved an example from memoryviews.rst to the examples directory.

parent 084a25f5
import numpy as np
def process_buffer(int[:,:] input_view not None,
int[:,:] output_view=None):
if output_view is None:
# Creating a default view, e.g.
output_view = np.empty_like(input_view)
# process 'input_view' into 'output_view'
return output_view
...@@ -71,14 +71,9 @@ This also works conveniently as function arguments: ...@@ -71,14 +71,9 @@ This also works conveniently as function arguments:
The ``not None`` declaration for the argument automatically rejects The ``not None`` declaration for the argument automatically rejects
None values as input, which would otherwise be allowed. The reason why None values as input, which would otherwise be allowed. The reason why
None is allowed by default is that it is conveniently used for return None is allowed by default is that it is conveniently used for return
arguments:: arguments:
def process_buffer(int[:,:] input not None, .. literalinclude:: ../../examples/userguide/memoryviews/not_none.pyx
int[:,:] output = None):
if output is None:
output = ... # e.g. numpy.empty_like(input)
# process 'input' into 'output'
return output
Cython will reject incompatible buffers automatically, e.g. passing a Cython will reject incompatible buffers automatically, e.g. passing a
three dimensional buffer into a function that requires a two three dimensional buffer into a function that requires a two
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment