diff options
author | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-26 20:42:49 +0200 |
---|---|---|
committer | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-26 20:42:49 +0200 |
commit | ea65eed85ebc686ab5f8b19c6cd874e8064fbca3 (patch) | |
tree | 775b38fa788ca894ed3e09d564550e2ef81a3b24 | |
parent | 084a25f55d0b4cf8b4c3cd496ec57bb3e2f57f71 (diff) | |
download | cython-ea65eed85ebc686ab5f8b19c6cd874e8064fbca3.tar.gz |
Moved an example from memoryviews.rst to the examples directory.
-rw-r--r-- | docs/examples/userguide/memoryviews/not_none.pyx | 11 | ||||
-rw-r--r-- | docs/src/userguide/memoryviews.rst | 11 |
2 files changed, 14 insertions, 8 deletions
diff --git a/docs/examples/userguide/memoryviews/not_none.pyx b/docs/examples/userguide/memoryviews/not_none.pyx new file mode 100644 index 000000000..ae3b6c936 --- /dev/null +++ b/docs/examples/userguide/memoryviews/not_none.pyx @@ -0,0 +1,11 @@ +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
diff --git a/docs/src/userguide/memoryviews.rst b/docs/src/userguide/memoryviews.rst index 82563d250..c5a18489f 100644 --- a/docs/src/userguide/memoryviews.rst +++ b/docs/src/userguide/memoryviews.rst @@ -71,14 +71,9 @@ This also works conveniently as function arguments: The ``not None`` declaration for the argument automatically rejects 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 -arguments:: - - def process_buffer(int[:,:] input not None, - int[:,:] output = None): - if output is None: - output = ... # e.g. numpy.empty_like(input) - # process 'input' into 'output' - return output +arguments: + +.. literalinclude:: ../../examples/userguide/memoryviews/not_none.pyx Cython will reject incompatible buffers automatically, e.g. passing a three dimensional buffer into a function that requires a two |