summaryrefslogtreecommitdiff
path: root/tests/memoryview/cfunc_convert_with_memoryview.pyx
blob: 55bd022052d334cfc2d493278ea530e13b6a96f3 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# mode: run
# tag: autowrap
# cython: always_allow_keywords=True

cdef void memoryview_func_a(double [:] x):
    x[0] = 1

cdef void memoryview_func_b(double [::1] x):
    x[0] = 2

cdef void memoryview_func_c(int [:] x):
    x[0] = 1

cdef void memoryview_func_d(int [:] x):
    x[0] = 2

cdef void memoryview_func_e(int [:,::1] x):
    x[0,0] = 4

cdef void memoryview_func_f(int [::1,:] x):
    x[0,0] = 4


def test_memview_wrapping():
    """
    We're mainly concerned that the code compiles without the names clashing
    >>> test_memview_wrapping()
    1.0
    2.0
    1
    2
    """
    cdef a = memoryview_func_a
    cdef b = memoryview_func_b
    cdef c = memoryview_func_c
    cdef d = memoryview_func_d
    cdef e = memoryview_func_e
    cdef f = memoryview_func_f
    cdef double[1] double_arr = [0]
    cdef int[1] int_arr = [0]

    a(<double[:1]> double_arr)
    print(double_arr[0])
    b(<double[:1:1]> double_arr)
    print(double_arr[0])
    c(<int[:1]> int_arr)
    print(int_arr[0])
    d(<int[:1:1]> int_arr)
    print(int_arr[0])
    # don't call e and f because it's harder without needing extra dependencies
    # it's mostly a compile test for them