File: w_numpy_arr_as_cppvec_ref.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (33 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download
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
# mode: error
# tag: cpp, werror, numpy, no-cpp-locals

import numpy as np
cimport numpy as np
from libcpp.vector cimport vector

np.import_array()

cdef extern from *:
    void cpp_function_vector1(vector[int])
    void cpp_function_vector2(vector[int] &)
    void cpp_function_2_vec_refs(vector[int] &, vector[int] &)


def main():
    cdef np.ndarray[int, ndim=1, mode="c"] arr = np.zeros(10, dtype='intc')
    cpp_function_vector1(arr)
    cpp_function_vector2(arr)
    cpp_function_vector2(arr)
    cpp_function_2_vec_refs(arr, arr)

    cdef vector[int] vec
    vec.push_back(0)
    cpp_function_vector2(vec)


_ERRORS = """
19:25: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
20:25: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
21:28: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
21:33: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
"""