本文整理汇总了Python中numba.function_util.external_call函数的典型用法代码示例。如果您正苦于以下问题:Python external_call函数的具体用法?Python external_call怎么用?Python external_call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了external_call函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: str_to_int
def str_to_int(self, dst_type, node):
# TODO: int <-> string conversions are explicit, this should not
# TODO: be a coercion
if self.nopython:
node = nodes.CoercionNode(
function_util.external_call(
self.context,
self.llvm_module,
('atol' if dst_type.is_int else 'atof'),
args=[node.node]),
dst_type, name=node.name, )
else:
if dst_type.is_int:
cvtobj = function_util.external_call(
self.context,
self.llvm_module,
'PyInt_FromString' if not PY3 else 'PyLong_FromString',
args=[node.node, nodes.NULL,
nodes.const(10, int_)])
else:
cvtobj = function_util.external_call(
self.context,
self.llvm_module,
'PyFloat_FromString',
args=[node.node,
nodes.const(0, Py_ssize_t)])
node = nodes.CoerceToNative(nodes.ObjectTempNode(cvtobj),
dst_type, name=node.name)
result = self.visit(node)
return result
示例2: visit_Slice
def visit_Slice(self, node):
"""
Rewrite slice objects. Do this late in the pipeline so that other
code can still recognize the code structure.
"""
slice_values = [node.lower, node.upper, node.step]
if self.nopython:
raise error.NumbaError(node, "Cannot slice in nopython context")
if node.variable.is_constant:
return self.visit(nodes.ObjectInjectNode(node.variable.constant_value))
bounds = []
for node in slice_values:
if node is None:
bounds.append(nodes.NULL_obj)
else:
bounds.append(node)
new_slice = function_util.external_call(self.context,
self.llvm_module,
'PySlice_New',
args=bounds,
temp_name='slice')
return self.visit(new_slice)
示例3: _object_binop
def _object_binop(self, node, api_name):
return self.visit(
function_util.external_call(self.context,
self.llvm_module,
api_name,
args=[node.left,
node.right]))
示例4: getiter
def getiter(self, context, for_node, llvm_module):
iterator = function_util.external_call(context, llvm_module,
self.getiter_func,
args=[for_node.iter])
iterator = nodes.CloneableNode(iterator)
self.iterator = iterator.clone
return iterator
示例5: visit_Attribute
def visit_Attribute(self, node):
if (self.nopython and not node.value.type.is_module and
not node.value.type.is_complex):
raise error.NumbaError(
node, "Cannot access Python attribute in nopython context (%s)" % node.attr)
if node.value.type.is_complex:
value = self.visit(node.value)
return nodes.ComplexAttributeNode(value, node.attr)
elif node.type.is_numpy_attribute:
return nodes.ObjectInjectNode(node.type.value)
elif node.type.is_numpy_dtype:
dtype_type = node.type.dtype
return nodes.ObjectInjectNode(dtype_type.get_dtype())
elif is_obj(node.value.type):
if node.value.type.is_module:
# Resolve module attributes as constants
if node.type.is_module_attribute:
new_node = nodes.ObjectInjectNode(node.type.value)
else:
new_node = nodes.ConstNode(getattr(node.value.type.module,
node.attr))
else:
new_node = function_util.external_call(
self.context,
self.llvm_module,
'PyObject_GetAttrString',
args=[node.value,
nodes.ConstNode(node.attr)])
return self.visit(new_node)
self.generic_visit(node)
return node
示例6: _object_Pow
def _object_Pow(self, node):
args = [node.left,
node.right,
nodes.ObjectInjectNode(None)]
return self.visit(function_util.external_call(self.context,
self.llvm_module,
'PyNumber_Power',
args=args),
llvm_module=self.llvm_module)
示例7: _raise_exception
def _raise_exception(self, body, node):
if node.exc_type:
assert node.exc_msg
if node.exc_args:
args = [node.exc_type, node.exc_msg] + node.exc_args
raise_node = function_util.external_call(self.context,
self.llvm_module,
'PyErr_Format',
args=args)
else:
args = [node.exc_type, node.exc_msg]
raise_node = function_util.external_call(self.context,
self.llvm_module,
'PyErr_SetString',
args=args)
body.append(raise_node)
示例8: _object_Not
def _object_Not(self, node):
callnode = function_util.external_call(self.function_cache,
self.llvm_module,
'PyObject_IsTrue',
args=[node.operand])
cmpnode = ast.Compare(callnode, [nodes.Eq()], [nodes.ConstNode(0)])
return self.visit(nodes.IfExp(cmpnode,
nodes.ObjectInjectNode(True),
nodes.ObjectInjectNode(False)))
示例9: visit_CoerceToObject
def visit_CoerceToObject(self, node):
new_node = node
node_type = node.node.type
if node_type.is_numeric:
cls = None
args = node.node,
if node_type.is_int:
cls = self._get_int_conversion_func(node_type,
pyapi._from_long)
elif node_type.is_float:
cls = pyapi.PyFloat_FromDouble
elif node_type.is_complex:
cls = pyapi.PyComplex_FromDoubles
complex_value = nodes.CloneableNode(node.node)
args = [
nodes.ComplexAttributeNode(complex_value, "real"),
nodes.ComplexAttributeNode(complex_value.clone, "imag")
]
else:
raise error.NumbaError(
node, "Don't know how to coerce type %r to PyObject" %
node_type)
if cls:
new_node = function_util.external_call(self.context,
self.llvm_module,
cls.__name__,
args=args)
elif node_type.is_pointer and not node_type.is_string():
# Create ctypes pointer object
ctypes_pointer_type = node_type.to_ctypes()
args = [nodes.CoercionNode(node.node, int64),
nodes.ObjectInjectNode(ctypes_pointer_type, object_)]
new_node = nodes.call_pyfunc(ctypes.cast, args)
elif node_type.is_bool:
new_node = function_util.external_call(self.context,
self.llvm_module,
"PyBool_FromLong",
args=[node.node])
self.generic_visit(new_node)
return new_node
示例10: visit_PyErr_OccurredNode
def visit_PyErr_OccurredNode(self, node):
check_err = nodes.CheckErrorNode(
nodes.ptrtoint(function_util.external_call(
self.context,
self.llvm_module,
'PyErr_Occurred')),
goodval=nodes.ptrtoint(nodes.NULL))
result = nodes.CloneableNode(node.node)
result = nodes.ExpressionNode(stmts=[result, check_err],
expr=result.clone)
return self.visit(result)
示例11: _resolve_int_number
def _resolve_int_number(self, func, node, argtype, dst_type, ext_name):
assert len(node.args) == 2
arg1, arg2 = node.args
if arg1.variable.type.is_c_string:
return nodes.CoercionNode(
nodes.ObjectTempNode(
function_util.external_call(
self.context,
self.llvm_module,
ext_name,
args=[arg1, nodes.NULL, arg2])),
dst_type=dst_type)
示例12: _print
def _print(self, value, dest=None):
signature, lfunc = self.context.external_library.declare(
self.llvm_module,
'PyObject_CallMethod')
if dest is None:
dest = nodes.ObjectInjectNode(sys.stdout)
value = function_util.external_call(self.context,
self.llvm_module,
"PyObject_Str",
args=[value])
args = [dest, nodes.ConstNode("write"), nodes.ConstNode("O"), value]
return nodes.NativeCallNode(signature, args, lfunc)
示例13: single_compare_objects
def single_compare_objects(self, node):
op = type(node.ops[0])
if op not in opmap:
raise error.NumbaError(
node, "%s comparisons not yet implemented" % (op,))
# Build arguments for PyObject_RichCompareBool
operator = nodes.const(opmap[op], int_)
args = [node.left, node.comparators[0], operator]
# Call PyObject_RichCompareBool
compare = function_util.external_call(self.context,
self.llvm_module,
'PyObject_RichCompareBool',
args=args)
# Coerce int result to bool
return nodes.CoercionNode(compare, bool_)
示例14: _print_nopython
def _print_nopython(self, value, dest=None):
if dest is not None:
raise error.NumbaError(dest, "No file may be given in nopython mode")
# stdin, stdout, stderr = stdio_util.get_stdio_streams()
# stdout = stdio_util.get_stream_as_node(stdout)
format = codegen.get_printf_specifier(value.type)
if format is None:
raise error.NumbaError(
value, "Printing values of type '%s' is not supported "
"in nopython mode" % (value.type,))
return function_util.external_call(
self.context,
self.llvm_module,
'printf',
args=[nodes.const(format, c_string_type),
value])
示例15: visit_Subscript
def visit_Subscript(self, node):
if isinstance(node.value, nodes.ArrayAttributeNode):
if node.value.is_read_only and isinstance(node.ctx, ast.Store):
raise error.NumbaError("Attempt to load read-only attribute")
# Short-circuit visiting a Slice child if this is a nopython
# string slice.
if (self.nopython and node.value.type.is_string and
node.type.is_string):
return self.visit(self._c_string_slice(node))
# logging.debug(ast.dump(node))
# TODO: do this in the respective cases below when needed
self.generic_visit(node)
node_type = node.value.type
if ((node_type.is_object and not node_type.is_array) or
(node_type.is_array and node.slice.type.is_object)):
# Array or object slicing
if isinstance(node.ctx, ast.Load):
result = function_util.external_call(self.context,
self.llvm_module,
'PyObject_GetItem',
args=[node.value,
node.slice])
node = nodes.CoercionNode(result, dst_type=node.type)
node = self.visit(node)
else:
# This is handled in visit_Assign
pass
elif (node.value.type.is_array and not node.type.is_array and
node.slice.type.is_int):
# Array index with integer indices
node = nodes.DataPointerNode(node.value, node.slice, node.ctx)
elif node.value.type.is_string and node.type.is_string:
node.value = nodes.CoercionNode(node.value, dst_type = object_)
node.type = object_
node = nodes.CoercionNode(nodes.ObjectTempNode(node),
dst_type = c_string_type)
node = self.visit(node)
return node