File: cython_test2.pyx

package info (click to toggle)
python-geotiepoints 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,876 kB
  • sloc: python: 3,148; makefile: 111; sh: 15
file content (34 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# cython: language_level=3, boundscheck=False, cdivision=True, wraparound=False, initializedcheck=False, nonecheck=False
cimport cython
import numpy as np
cimport numpy as np

np.import_array()

def test_func():
    cdef np.ndarray[float, ndim=2] arr = np.zeros((5, 5), dtype=np.float32)
    cdef float[:, ::1] arr_view = arr
    t = Test(5.0)
    t.call_me(arr_view)


cdef class Test:

    cdef float _a

    def __cinit__(self, float a):
        self._a = a

    cdef void call_me(self, float[:, ::1] my_arr) noexcept:
        with nogil:
            self._call_me(my_arr)

    cdef void _call_me(self, float[:, ::1] my_arr) noexcept nogil:
        cdef Py_ssize_t idx
        cdef float[:, :] my_arr2 = _get_upper_left_corner(my_arr)
        for idx in range(my_arr2.shape[0]):
            my_arr2[idx, 0] = self._a


cdef inline float[:, :] _get_upper_left_corner(float[:, ::1] arr) noexcept nogil:
    return arr[:3, :3]