本文整理汇总了Python中weave.inline_tools.inline函数的典型用法代码示例。如果您正苦于以下问题:Python inline函数的具体用法?Python inline怎么用?Python inline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inline函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:27,代码来源:test_inline_tools.py
示例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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:26,代码来源:test_scxx_sequence.py
示例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)
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:7,代码来源:test_scxx_object.py
示例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)
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:7,代码来源:test_scxx_object.py
示例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)
开发者ID:SamyStyle,项目名称:weave,代码行数:7,代码来源:test_scxx_object.py
示例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)
开发者ID:SamyStyle,项目名称:weave,代码行数:25,代码来源:test_scxx_object.py
示例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)
开发者ID:apetcho,项目名称:weave,代码行数:26,代码来源:test_scxx_sequence.py
示例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)
开发者ID:SamyStyle,项目名称:weave,代码行数:28,代码来源:test_scxx_sequence.py
示例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)
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:7,代码来源:test_scxx_object.py
示例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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:25,代码来源:test_scxx_sequence.py
示例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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:32,代码来源:test_scxx_sequence.py
示例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)
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:7,代码来源:test_scxx_object.py
示例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)
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:26,代码来源:test_scxx_sequence.py
示例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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:34,代码来源:test_scxx_sequence.py
示例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
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:28,代码来源:test_scxx_sequence.py
示例16: test_int_add_speed
def test_int_add_speed(self):
N = 1000000
debug_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()
debug_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()
debug_print('weave:', t2 - t1)
assert_(b == desired)
开发者ID:apetcho,项目名称:weave,代码行数:25,代码来源:test_scxx_sequence.py
示例17: test_set_complex
def test_set_complex(self):
a = UserDict()
key = 1+1j
inline_tools.inline("a[key] = 1234;",['a','key'])
assert_equal(sys.getrefcount(key),4) # should be 3
assert_equal(sys.getrefcount(a[key]),2)
assert_equal(a[key],1234)
开发者ID:SamyStyle,项目名称:weave,代码行数:7,代码来源:test_scxx_object.py
示例18: check_count
def check_count(self,level=5):
""" Test the "count" method for lists. We'll assume
it works for sequences if it works hre.
"""
a = self.seq_type([1,2,'alpha',3.1416])
item = 1
code = "return_val = a.count(item);"
res = inline_tools.inline(code,['a','item'])
assert res == 1
# check overloaded count(int val) method
code = "return_val = a.count(1);"
res = inline_tools.inline(code,['a'])
assert res == 1
# check overloaded count(double val) method
code = "return_val = a.count(3.1416);"
res = inline_tools.inline(code,['a'])
assert res == 1
# check overloaded count(char* val) method
code = 'return_val = a.count("alpha");'
res = inline_tools.inline(code,['a'])
assert res == 1
# check overloaded count(std::string val) method
code = """
std::string alpha = std::string("alpha");
return_val = a.count(alpha);
"""
res = inline_tools.inline(code,['a'])
assert res == 1
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:33,代码来源:test_scxx_sequence.py
示例19: check_set_item_operator_equal_fail
def check_set_item_operator_equal_fail(self,level=5):
# Tuples should only allow setting of variables
# immediately after creation.
a = (1,2,3)
try:
inline_tools.inline("a[1] = 1234;",['a'])
except TypeError:
pass
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:8,代码来源:test_scxx_sequence.py
示例20: test_conversion
def test_conversion(self):
a = self.seq_type([1])
before = sys.getrefcount(a)
inline_tools.inline(" ",['a'])
# first call is goofing up refcount.
before = sys.getrefcount(a)
inline_tools.inline(" ",['a'])
after = sys.getrefcount(a)
assert_(after == before)
开发者ID:apetcho,项目名称:weave,代码行数:9,代码来源:test_scxx_sequence.py
注:本文中的weave.inline_tools.inline函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论