根据Cython文档,我编写了以下cython代码如下:
\n\nIn [1]:%load_ext Cython\nIn [2]: %%cython\n from libcpp.vector cimport vector\n\xe2\x80\x8b cdef vector[int] *vec_int = new vector[int](10)\nRun Code Online (Sandbox Code Playgroud)\n\n编译后,ipython产生以下错误:
\n\nError compiling Cython file:\n------------------------------------------------------------ \n... \nfrom libcpp.vector cimport vector \ncdef vector[int] *vec_int = new vector[int](10) \n ^ \n------------------------------------------------------------\n/Users/m/.ipython/cython/_cython_magic_a72abb419ccf1b31db9a1851b522a4bf.pyx:3:32: Operation only allowed in c++\nRun Code Online (Sandbox Code Playgroud)\n\n我的代码有什么问题吗?
\n现在我正在使用EnvInject 插件通过属性文件将我的环境变量插入到我的 Jenkins 作业中。
但是,现在我有第二份工作,它需要与第一份工作相同的环境变量,而不是我想通过另一个属性文件加载的更多附加变量。
我知道,可以通过 EnvInject-plugin 的 Properties Content Edit 字段插入值,但我想将它保存在一个文件中,以便可以在作业之间共享。但是似乎不可能向 EnvInject-plugin 添加第二个属性文件。
有什么方法可以将多个属性文件注入到作业或任何其他插件中,以处理我的情况?
当我尝试用另一个类的方法对一个类进行猴子修补时,它不起作用,因为参数self的类型不正确。
例如,让我们喜欢__str__fancy类创建的方法的结果A:
class A:
def __init__(self, val):
self.val=val
def __str__(self):
return "Fancy formatted %s"%self.val
Run Code Online (Sandbox Code Playgroud)
并希望将其重用于无聊的课程B:
class B:
def __init__(self, val):
self.val=val
Run Code Online (Sandbox Code Playgroud)
这意味着:
>>> b=B("B")
>>> #first try:
>>> B.__str__=A.__str__
>>> str(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method __str__() must be called with A instance as first argument (got nothing instead)
>>> #second try:
>>> B.__str__= lambda self: A.__str__(self)
>>> str(b)
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud) 当我在调试模式下使用 VisualStudio 编译程序运行我的程序时,有时我会得到
调试断言失败!表达:
_CrtIsValidHeapPointer(block)
或者
调试断言失败!表达:
is_block_type_valid(header->_block_use)
(或两者之后)断言。
这是什么意思?如何找到并修复此类问题的根源?
我试图将C代码公开给cython,并尝试使用另一个cython模块中的c文件中定义的函数时遇到“未定义符号”错误。
我的h文件中定义的函数以及使用手动包装的函数都可以正常工作。
基本上与这个问题相同,但是解决方案(针对库的链接)对我来说并不令人满意。
我认为我在setup.py脚本中缺少什么?
foo.h
int source_func(void);
inline int header_func(void){
return 1;
}
Run Code Online (Sandbox Code Playgroud)
foo.c
#include "foo.h"
int source_func(void){
return 2;
}
Run Code Online (Sandbox Code Playgroud)
cdef extern from "foo.h":
int source_func()
int header_func()
cdef source_func_wrapper()
Run Code Online (Sandbox Code Playgroud)
foo_wrapper.pyx
cdef source_func_wrapper():
return source_func()
Run Code Online (Sandbox Code Playgroud)
cimport foo_wrapper
def do_it():
print "header func"
print foo_wrapper.header_func() # ok
print "source func wrapped"
print foo_wrapper.source_func_wrapper() # ok
print "source func"
print foo_wrapper.source_func() # undefined symbol: source_func
Run Code Online (Sandbox Code Playgroud)
foo_wrapper和test_lib
cdef extern from …Run Code Online (Sandbox Code Playgroud) 在我们的旧C/C++代码中,我遇到了两个版本的签名
void foo1(double *vec, int n)
Run Code Online (Sandbox Code Playgroud)
和
void foo2(double vec[], int n)
Run Code Online (Sandbox Code Playgroud)
但是vec方法内部参数的处理没有区别,例如:
void foo2(double vec[], int n){
for(int i=0;i<n;i++)
do_something(vec[i]);
}
Run Code Online (Sandbox Code Playgroud)
第一个版本(double *)和第二个版本()之间有什么区别double ..[]吗?在哪种情况下,一个版本应该优先于另一个?
编辑:在@ Khaled.KI的提示尝试编译之后:
void foo(double *d, int n){}
void foo(double d[], int n){}
Run Code Online (Sandbox Code Playgroud)
由于重新定义void而导致编译错误foo(double *d, int n).所以double *vec并且double vec[]意思相同.
仍然存在的问题是何时应该使用哪个版本.