def visit_MathNode(self, math_node): "Translate a nodes.MathNode to an intrinsic or libc math call" from numba.type_inference.modules import mathmodule lowerable = is_math_function([math_node.arg], math_node.py_func) if math_node.type.is_array or not lowerable: # Generate a Python call assert math_node.py_func is not None result = nodes.call_pyfunc(math_node.py_func, [math_node.arg]) result = result.coerce(math_node.type) else: # Lower to intrinsic or libc math call args = [math_node.arg], math_node.py_func, math_node.type if is_intrinsic(math_node.py_func): result = resolve_intrinsic(*args) else: result = resolve_libc_math(*args) return self.visit(result)
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
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
def _resolve_round(self, func, node, argtype): if is_math_function(node.args, round): # round() always returns a float return resolve_math_call(node, round) return None