本文整理汇总了Python中weave.inline_tools.inline函数的典型用法代码示例。如果您正苦于以下问题:Python inline函数的具体用法?Python inline怎么用?Python inline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_exceptions
def check_exceptions(self,level=5):
a = 3
code = """
if (a < 2)
throw_error(PyExc_ValueError,
"the variable 'a' should not be less than 2");
else
return_val = PyInt_FromLong(a+1);
"""
result = inline_tools.inline(code,['a'])
assert(result == 4)
try:
a = 1
result = inline_tools.inline(code,['a'])
assert(1) # should've thrown a ValueError
except ValueError:
pass
from distutils.errors import DistutilsError, CompileError
try:
a = 'string'
result = inline_tools.inline(code,['a'])
assert(1) # should've gotten an error
except:
# ?CompileError is the error reported, but catching it doesn't work
pass
示例2: check_string_add_speed
def check_string_add_speed(self,level=5):
N = 1000000
print 'string add -- b[i] = a[i] + "blah" for N =', N
a = ["blah"] * N
desired = [1] * N
t1 = time.time()
for i in xrange(N):
desired[i] = a[i] + 'blah'
t2 = time.time()
print 'python:', t2 - t1
a = ["blah"] * N
b = [1] * N
code = """
const int N = a.length();
std::string blah = std::string("blah");
for(int i=0; i < N; i++)
b[i] = (std::string)a[i] + blah;
"""
# compile not included in timing
inline_tools.inline(code,['a','b'])
t1 = time.time()
inline_tools.inline(code,['a','b'])
t2 = time.time()
print 'weave:', t2 - t1
assert b == desired
示例3: check_list_refcount
def check_list_refcount(self,level=5):
a = UserList([1,2,3])
# temporary refcount fix until I understand why it incs by one.
inline_tools.inline("a[1] = 1234;",['a'])
before1 = sys.getrefcount(a)
after1 = sys.getrefcount(a)
assert_equal(after1,before1)
示例4: check_complex_cast
def check_complex_cast(self,level=5):
code = """
std::complex<double> num = std::complex<double>(1.0,1.0);
py::object val = num;
std::complex<double> raw_val = val;
"""
inline_tools.inline(code)
示例5: test_complex_cast
def test_complex_cast(self):
code = """
std::complex<double> num = std::complex<double>(1.0, 1.0);
py::object val = num;
std::complex<double> raw_val __attribute__ ((unused)) = val;
"""
inline_tools.inline(code)
示例6: test_noargs_with_args_not_instantiated
def test_noargs_with_args_not_instantiated(self):
# calling a function that doesn't take args with args should fail.
# Note: difference between this test add ``test_noargs_with_args``
# below is that here Foo is not instantiated.
def Foo():
return "blah"
code = """
py::tuple args(2);
args[0] = 1;
args[1] = "hello";
return_val = Foo.call(args);
"""
try:
first = sys.getrefcount(Foo)
inline_tools.inline(code,['Foo'])
except TypeError:
second = sys.getrefcount(Foo)
try:
inline_tools.inline(code,['Foo'])
except TypeError:
third = sys.getrefcount(Foo)
# first should == second, but the weird refcount error
assert_equal(second,third)
示例7: test_string_add_speed
def test_string_add_speed(self):
N = 1000000
debug_print('string add -- b[i] = a[i] + "blah" for N =', N)
a = ["blah"] * N
desired = [1] * N
t1 = time.time()
for i in xrange(N):
desired[i] = a[i] + 'blah'
t2 = time.time()
debug_print('python:', t2 - t1)
a = ["blah"] * N
b = [1] * N
code = """
const int N = a.length();
std::string blah = std::string("blah");
for(int i=0; i < N; i++)
b[i] = convert_to_string(a[i],"a") + blah;
"""
# compile not included in timing
inline_tools.inline(code,['a','b'])
t1 = time.time()
inline_tools.inline(code,['a','b'])
t2 = time.time()
debug_print('weave:', t2 - t1)
assert_(b == desired)
示例8: test_access_speed
def test_access_speed(self):
N = 1000000
debug_print('%s access -- val = a[i] for N =', (self.seq_type, N))
a = self.seq_type([0]) * N
val = 0
t1 = time.time()
for i in range(N):
val = a[i]
t2 = time.time()
debug_print('python1:', t2 - t1)
t1 = time.time()
for i in a:
val = i
t2 = time.time()
debug_print('python2:', t2 - t1)
code = """
const int N = a.length();
py::object val;
for(int i=0; i < N; i++)
val = a[i];
"""
# compile not included in timing
inline_tools.inline(code,['a'])
t1 = time.time()
inline_tools.inline(code,['a'])
t2 = time.time()
debug_print('weave:', t2 - t1)
示例9: check_set_double_new
def check_set_double_new(self,level=5):
a = UserDict()
key = 1.0
inline_tools.inline('a[key] = 123.0;',['a','key'])
assert_equal(sys.getrefcount(key),4) # should be 3
assert_equal(sys.getrefcount(a[key]),2)
assert_equal(a[key],123.0)
示例10: check_int_add_speed
def check_int_add_speed(self,level=5):
N = 1000000
print 'int add -- b[i] = a[i] + 1 for N =', N
a = [0] * N
desired = [1] * N
t1 = time.time()
for i in xrange(N):
desired[i] = a[i] + 1
t2 = time.time()
print 'python:', t2 - t1
a = [0] * N
b = [0] * N
code = """
const int N = a.length();
for(int i=0; i < N; i++)
b[i] = (int)a[i] + 1;
"""
# compile not included in timing
inline_tools.inline(code,['a','b'])
t1 = time.time()
inline_tools.inline(code,['a','b'])
t2 = time.time()
print 'weave:', t2 - t1
assert b == desired
示例11: check_set_item_operator_equal
def check_set_item_operator_equal(self,level=5):
a = self.seq_type([1,2,3])
# temporary refcount fix until I understand why it incs by one.
inline_tools.inline("a[1] = 1234;",['a'])
before1 = sys.getrefcount(a)
# check overloaded insert(int ndx, int val) method
inline_tools.inline("a[1] = 1234;",['a'])
assert sys.getrefcount(a[1]) == 2
assert a[1] == 1234
# check overloaded insert(int ndx, double val) method
inline_tools.inline("a[1] = 123.0;",['a'])
assert sys.getrefcount(a[1]) == 2
assert a[1] == 123.0
# check overloaded insert(int ndx, char* val) method
inline_tools.inline('a[1] = "bubba";',['a'])
assert sys.getrefcount(a[1]) == 2
assert a[1] == 'bubba'
# check overloaded insert(int ndx, std::string val) method
code = """
std::string val = std::string("sissy");
a[1] = val;
"""
inline_tools.inline(code,['a'])
assert sys.getrefcount(a[1]) == 2
assert a[1] == 'sissy'
after1 = sys.getrefcount(a)
assert after1 == before1
示例12: check_set_complex
def check_set_complex(self,level=5):
a = UserDict()
key = 1+1j
inline_tools.inline("a[key] = 1234;",['a','key'])
assert_equal(sys.getrefcount(key),3)
assert_equal(sys.getrefcount(a[key]),2)
assert_equal(a[key],1234)
示例13: check_access_set_speed
def check_access_set_speed(self,level=5):
N = 1000000
print '%s access/set -- b[i] = a[i] for N =', (self.seq_type,N)
a = self.seq_type([0]) * N
# b is always a list so we can assign to it.
b = [1] * N
t1 = time.time()
for i in xrange(N):
b[i] = a[i]
t2 = time.time()
print 'python:', t2 - t1
a = self.seq_type([0]) * N
b = [1] * N
code = """
const int N = a.length();
for(int i=0; i < N; i++)
b[i] = a[i];
"""
# compile not included in timing
inline_tools.inline(code,['a','b'])
t1 = time.time()
inline_tools.inline(code,['a','b'])
t2 = time.time()
print 'weave:', t2 - t1
assert list(b) == list(a)
示例14: check_append
def check_append(self,level=5):
a = []
# temporary refcount fix until I understand why it incs by one.
inline_tools.inline("a.append(1);",['a'])
del a[0]
before1 = sys.getrefcount(a)
# check overloaded append(int val) method
inline_tools.inline("a.append(1234);",['a'])
assert sys.getrefcount(a[0]) == 2
assert a[0] == 1234
del a[0]
# check overloaded append(double val) method
inline_tools.inline("a.append(123.0);",['a'])
assert sys.getrefcount(a[0]) == 2
assert a[0] == 123.0
del a[0]
# check overloaded append(char* val) method
inline_tools.inline('a.append("bubba");',['a'])
assert sys.getrefcount(a[0]) == 2
assert a[0] == 'bubba'
del a[0]
# check overloaded append(std::string val) method
inline_tools.inline('a.append(std::string("sissy"));',['a'])
assert sys.getrefcount(a[0]) == 2
assert a[0] == 'sissy'
del a[0]
after1 = sys.getrefcount(a)
assert after1 == before1
示例15: check_access_speed
def check_access_speed(self,level=5):
N = 1000000
print '%s access -- val = a[i] for N =', (self.seq_type, N)
a = self.seq_type([0]) * N
val = 0
t1 = time.time()
for i in xrange(N):
val = a[i]
t2 = time.time()
print 'python1:', t2 - t1
t1 = time.time()
for i in a:
val = i
t2 = time.time()
print 'python2:', t2 - t1
code = """
const int N = a.length();
py::object val;
for(int i=0; i < N; i++)
val = a[i];
"""
# compile not included in timing
inline_tools.inline(code,['a'])
t1 = time.time()
inline_tools.inline(code,['a'])
t2 = time.time()
print 'weave:', t2 - t1