本文整理汇总了Python中nitrous.module.module函数的典型用法代码示例。如果您正苦于以下问题:Python module函数的具体用法?Python module怎么用?Python module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了module函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_branch_elimination
def test_branch_elimination(self):
from nitrous.module import dump
add_5 = False
add_any = True
@function(Long, a=Long, b=Bool)
def f1(a, b):
if add_any and b:
a += 5
return a
@function(Long, a=Long)
def f2(a):
if add_any and add_5:
a += 5
return a
m1 = module([f1])
ir = " ".join(dump(m1).split("\n"))
# In first function, conditional depends on a parameter
self.assertRegexpMatches(ir, "icmp")
m2 = module([f2])
ir = " ".join(dump(m2).split("\n"))
# In second, entire conditional is resolved at
# compile time and optimized away
self.assertNotRegexpMatches(ir, "icmp")
示例2: test_not_iterable
def test_not_iterable(self):
@function(a=Long)
def foo(a):
b, = a
message = "Value of type 'Long' is not an iterable"
with self.assertRaisesRegexp(TypeError, message):
module([foo])
示例3: test_type_mismatch
def test_type_mismatch(self):
@function(Bool, x=Long)
def f1(x):
return x < 1.0
message = ">>> return x < 1.0"
with self.assertRaisesRegexp(TypeError, message):
module([f1])
示例4: test_assign_wrong_type
def test_assign_wrong_type(self):
@function(x=Array(Long, shape=(1,)), y=Double)
def f(x, y):
x[0] = y
message = ">>> x\[0\] = y"
with self.assertRaisesRegexp(TypeError, message):
module([f])
示例5: test_compound_test
def test_compound_test(self):
"""Support compound conditionals such as 1 < x < 2."""
@function(Bool, x=Long)
def f1(x):
return 1 < x < 2
message = ">>> return 1 < x < 2"
with self.assertRaisesRegexp(NotImplementedError, message):
module([f1])
示例6: test_unexpected_type
def test_unexpected_type(self):
"""Raise error if returning unexpected value type."""
@function(Double, x=Double)
def f(x):
return 5
message = ">>> return 5"
with self.assertRaisesRegexp(TypeError, message):
module([f])
示例7: test_missing_return
def test_missing_return(self):
"""Raise error if no return in function with non-void return type."""
@function(Double)
def f():
pass
message = ">>> pass"
with self.assertRaisesRegexp(TypeError, message):
module([f])
示例8: test_shape_mismatch
def test_shape_mismatch(self):
"""Raise error if packed/unpacked tuple lengths differ"""
@function(Long, a=Long, b=Long)
def foo(a, b):
b, = a, b
message = "Cannot unpack 2 values into 1"
with self.assertRaisesRegexp(ValueError, message):
module([foo])
示例9: test_missing_symbol
def test_missing_symbol(self):
"""Raise error if cannot resolve a symbol."""
@function(Double, y=Long)
def x(y):
return z
error = ">>> return z"
with self.assertRaisesRegexp(NameError, error):
module([x])
示例10: test_return_non_void
def test_return_non_void(self):
"""Raise error if void function returns non-void value"""
@function()
def f():
return 5
message = ">>> return 5"
with self.assertRaisesRegexp(ValueError, message):
module([f])
示例11: test_unsupported_slice
def test_unsupported_slice(self):
"""Raise error on unsupported context (eg. `del x`)."""
@function(Long, y=Long)
def x(y):
y[:]
return 0
message = ">>> y\[:\]"
with self.assertRaisesRegexp(NotImplementedError, message):
module([x])
示例12: test_unsupported_target
def test_unsupported_target(self):
"""Check for unsupported assignments."""
@function(Long, a=Long, b=Long)
def f(a, b):
a, b = 1
return 0
message = ">>> a, b = 1"
with self.assertRaisesRegexp(TypeError, message):
module([f])
示例13: test_unsupported_chain
def test_unsupported_chain(self):
"""Raise error on chain assignment."""
@function(Long)
def f():
a = b = 1
return 0
message = ">>> a = b = 1"
with self.assertRaisesRegexp(NotImplementedError, message):
module([f])
示例14: test_if_expr_type_mismatch
def test_if_expr_type_mismatch(self):
"""Raise error when `if` expression clause types don't match."""
# Simple expression
@function(Long, a=Long, b=Long)
def max2(a, b):
return 1.0 if a > b else 0
message = ">>> return 1.0 if a > b else 0"
with self.assertRaisesRegexp(TypeError, message):
module([max2])
示例15: test_symbol_out_of_scope
def test_symbol_out_of_scope(self):
"""Raise error if symbol is available but not in the current scope."""
@function(Double, y=Long)
def x(y):
for i in range(y):
z = i
return z
error = ">>> return z"
with self.assertRaisesRegexp(NameError, error):
module([x])