diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-15 20:35:23 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-02-15 20:47:04 +0100 |
commit | b67e556756c82f99d633b82cc4652d0dfcdce3f7 (patch) | |
tree | 2c14538d202c1f8eeaa84a774da0cb7fc2e778a4 /docs/examples/userguide/numpy_tutorial/compute_memview.pyx | |
parent | e6a49ace494660793c3e8cd8115277784108dc40 (diff) | |
download | cython-b67e556756c82f99d633b82cc4652d0dfcdce3f7.tar.gz |
Fix line endings.
Diffstat (limited to 'docs/examples/userguide/numpy_tutorial/compute_memview.pyx')
-rw-r--r-- | docs/examples/userguide/numpy_tutorial/compute_memview.pyx | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/docs/examples/userguide/numpy_tutorial/compute_memview.pyx b/docs/examples/userguide/numpy_tutorial/compute_memview.pyx index d264e773a..166cd6df3 100644 --- a/docs/examples/userguide/numpy_tutorial/compute_memview.pyx +++ b/docs/examples/userguide/numpy_tutorial/compute_memview.pyx @@ -1,34 +1,34 @@ -import numpy as np
-
-DTYPE = np.intc
-
-
-cdef int clip(int a, int min_value, int max_value):
- return min(max(a, min_value), max_value)
-
-
-def compute(int[:, :] array_1, int[:, :] array_2, int a, int b, int c):
-
- cdef Py_ssize_t x_max = array_1.shape[0]
- cdef Py_ssize_t y_max = array_1.shape[1]
-
- # array_1.shape is now a C array, no it's not possible
- # to compare it simply by using == without a for-loop.
- # To be able to compare it to array_2.shape easily,
- # we convert them both to Python tuples.
- assert tuple(array_1.shape) == tuple(array_2.shape)
-
- result = np.zeros((x_max, y_max), dtype=DTYPE)
- cdef int[:, :] result_view = result
-
- cdef int tmp
- cdef Py_ssize_t x, y
-
- for x in range(x_max):
- for y in range(y_max):
-
- tmp = clip(array_1[x, y], 2, 10)
- tmp = tmp * a + array_2[x, y] * b
- result_view[x, y] = tmp + c
-
- return result
+import numpy as np + +DTYPE = np.intc + + +cdef int clip(int a, int min_value, int max_value): + return min(max(a, min_value), max_value) + + +def compute(int[:, :] array_1, int[:, :] array_2, int a, int b, int c): + + cdef Py_ssize_t x_max = array_1.shape[0] + cdef Py_ssize_t y_max = array_1.shape[1] + + # array_1.shape is now a C array, no it's not possible + # to compare it simply by using == without a for-loop. + # To be able to compare it to array_2.shape easily, + # we convert them both to Python tuples. + assert tuple(array_1.shape) == tuple(array_2.shape) + + result = np.zeros((x_max, y_max), dtype=DTYPE) + cdef int[:, :] result_view = result + + cdef int tmp + cdef Py_ssize_t x, y + + for x in range(x_max): + for y in range(y_max): + + tmp = clip(array_1[x, y], 2, 10) + tmp = tmp * a + array_2[x, y] * b + result_view[x, y] = tmp + c + + return result |