Commit b260846e authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2428 from gabrieldemarmiesse/test_memoryviews_1

Added tests for "typed memoryviews" part 1
parents e2742e7b ea65eed8
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