Cython,关于向量(大小)构造函数的混淆
Cython, confusion regarding the vector (size) constructor
编辑:仅供参考,现在遇到此问题的任何人只需使用 pybind11,不要在此(cython 东西)上浪费时间
似乎定义vector
变量的唯一方法是
cdef std::vector[int]* vec=new vector[int](<size>)
我这样想对吗?这是示例代码,如果我编译并运行此 Python 最后崩溃(VS2015,Python 3.5)。
from libcpp.vector cimport vector
def test():
cdef vector[int]* vec = new vector[int](5)
cdef int i
for i in range(5):
print(vec[i])
del vec
我想要一个具有一定大小的二维向量。我该怎么做?会不会是:
cdef std::vector[std::vector[int]]* vec=new vector[vector[int](<size1>)](<size2>)
尽管官方示例显示了如何在堆上创建这些东西,但由于某种原因,这并不是真正必要的。此代码构建:
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)
它构建了一个 5X5 的 int 向量。
相关文章:
- std::string 构造函数如何处理固定大小的 char[]?
- C++ - 移动具有固定大小的 c 样式数组成员的类的构造函数
- 动态构造函数中的新字符 [] 抛出"损坏的顶部大小";
- C++构造函数采用大小为1的std::initializer_list
- 如何在 C++ 中检查类构造函数中的参数大小
- 瓦尔格林德:构造函数中大小为 1 的无效读取
- 构造函数C++中未定义大小的数组
- 如何在类的构造函数中定义成员向量的大小
- 我如何通过构造函数大小私人std ::数组成员
- 通过在 constexpr 构造函数中传递 N,在编译时创建一个大小为 N 的数组
- C++变体:为什么转换构造函数需要大小.(类型)为非零
- 将未知类型和大小的 std::数组传递给模板化函数的构造函数
- C++:为什么 boost::p tr_vector 调整大小需要对象具有默认构造函数
- STD ::数组的初始大小在使用它的类的构造函数中
- 如何在类构造函数中设置 STL 队列的大小
- 在类的构造函数中为常量动态大小的数组赋值
- 向量大小在构造函数外部恢复为 0
- 提供成员数组的大小(const)作为构造函数参数RELOADED
- 创建大小元素的向量,而无需调用复制构造函数
- 在 std::vector 上调整大小不会调用移动构造函数