• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python function_util.external_call函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numba.function_util.external_call函数的典型用法代码示例。如果您正苦于以下问题:Python external_call函数的具体用法?Python external_call怎么用?Python external_call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了external_call函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:FrancescAlted,项目名称:numba,代码行数:30,代码来源:transforms.py


示例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)
开发者ID:FrancescAlted,项目名称:numba,代码行数:26,代码来源:transforms.py


示例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]))
开发者ID:FrancescAlted,项目名称:numba,代码行数:7,代码来源:transforms.py


示例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
开发者ID:dwf,项目名称:numba,代码行数:7,代码来源:loopimpl.py


示例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
开发者ID:FrancescAlted,项目名称:numba,代码行数:33,代码来源:transforms.py


示例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)
开发者ID:FrancescAlted,项目名称:numba,代码行数:9,代码来源:transforms.py


示例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)
开发者ID:hgrecco,项目名称:numba,代码行数:18,代码来源:exceptions.py


示例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)))
开发者ID:FrancescAlted,项目名称:numba,代码行数:9,代码来源:transforms.py


示例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
开发者ID:lizecillie,项目名称:numba,代码行数:43,代码来源:transforms.py


示例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)
开发者ID:hgrecco,项目名称:numba,代码行数:11,代码来源:exceptions.py


示例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)
开发者ID:lizecillie,项目名称:numba,代码行数:13,代码来源:transforms.py


示例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)
开发者ID:FrancescAlted,项目名称:numba,代码行数:14,代码来源:transforms.py


示例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_)
开发者ID:KanzhiWu,项目名称:numba,代码行数:18,代码来源:comparisons.py


示例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])
开发者ID:FrancescAlted,项目名称:numba,代码行数:19,代码来源:transforms.py


示例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
开发者ID:FrancescAlted,项目名称:numba,代码行数:42,代码来源:transforms.py


示例16: _trap

    def _trap(self, body, node):
        if node.exc_msg and node.print_on_trap:
            pos = error.format_pos(node)
            if node.exception_type:
                exc_type = '%s: ' % node.exception_type.__name__
            else:
                exc_type = ''

            msg = '%s%s%%s' % (exc_type, pos)
            format = nodes.const(msg, c_string_type)
            print_msg = function_util.external_call(self.context,
                                                    self.llvm_module,
                                                    'printf',
                                                    args=[format,
                                                          node.exc_msg])
            body.append(print_msg)

        trap = nodes.LLVMIntrinsicNode(signature=void(), args=[],
                                       func_name='TRAP')
        body.append(trap)
开发者ID:hgrecco,项目名称:numba,代码行数:20,代码来源:exceptions.py


示例17: _resolve_abs

    def _resolve_abs(self, func, node, argtype):
        is_math = is_math_function(node.args, abs)

        # TODO: generate efficient inline code
        if is_math and argtype.is_float:
            return resolve_math_call(node, abs)
        elif is_math and argtype.is_int:
            if argtype.signed:
                type = promote_closest(self.context, argtype, [long_, longlong])
                funcs = {long_: 'labs', longlong: 'llabs'}
                return function_util.external_call(
                                            self.context,
                                            self.llvm_module,
                                            funcs[type],
                                            args=[node.args[0]])
            else:
                # abs() on unsigned integral value
                return node.args[0]

        return None
开发者ID:lizecillie,项目名称:numba,代码行数:20,代码来源:transforms.py


示例18: visit_Assign

    def visit_Assign(self, node):
        target = node.targets[0]
        target_is_subscript = (len(node.targets) == 1 and
                               isinstance(target, ast.Subscript))
        if target_is_subscript and is_obj(target.type):
            # Slice assignment / index assignment w/ objects
            # TODO: discount array indexing with dtype object
            target = self.visit(target)
            obj = target.value
            key = target.slice
            value = self.visit(node.value)
            call = function_util.external_call(self.context,
                                               self.llvm_module,
                                               'PyObject_SetItem',
                                               args=[obj, key, value])
            return self.visit(call)

        elif target.type.is_struct and nodes.is_name(target):
            node = self.allocate_struct_on_stack(node, target)
            return node

        self.generic_visit(node)
        return node
开发者ID:FrancescAlted,项目名称:numba,代码行数:23,代码来源:transforms.py


示例19: next

 def next(self, context, for_node, llvm_module):
     return function_util.external_call(context, llvm_module, self.next_func, args=[self.iterator])
开发者ID:meteogrid,项目名称:numba,代码行数:2,代码来源:loopimpl.py


示例20: inject_print

def inject_print(context, module, node):
    node = function_util.external_call(context, module, "PyObject_Str", args=[node])
    node = function_util.external_call(context, module, "puts", args=[node])
    return node
开发者ID:jdchristensen,项目名称:numba,代码行数:4,代码来源:__init__.py



注:本文中的numba.function_util.external_call函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nodes.const函数代码示例发布时间:2022-05-27
下一篇:
Python dummyarray.Array类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap