python - Cython, confusion regarding the vector (size) constructor -
it seems way define vector
variable
cdef std::vector[int]* vec=new vector[int](<size>)
am correct in thinking this? here's sample code, if compile , run python crashes @ end (vs2015, python 3.5).
from libcpp.vector cimport vector def test(): cdef vector[int]* vec = new vector[int](5) cdef int in range(5): print(vec[i]) del vec
i want have 2 dimensional vector, size. how this? be:
cdef std::vector[std::vector[int]]* vec=new vector[vector[int](<size1>)](<size2>)
although official examples show how create stuff on heap, reason, it's not necessary. code builds:
from libcpp.vector cimport vector ctypedef vector[int] int_vec ctypedef vector[int_vec] int_vec_vec def test(): cdef int_vec v v = int_vec(5) cdef int_vec_ve vv vv = int_vec_vec(5, v)
it builds 5x5 vector of int vectors.
Comments
Post a Comment