numba.targets package

Submodules

numba.targets.arrayobj module

Implementation of operations on Array objects.

numba.targets.arrayobj.array_len(context, builder, sig, args)
numba.targets.arrayobj.array_ndim(context, builder, typ, value, attr)
numba.targets.arrayobj.array_record_getattr(context, builder, typ, value, attr)
numba.targets.arrayobj.array_shape(context, builder, typ, value, attr)
numba.targets.arrayobj.array_size(context, builder, typ, value, attr)
numba.targets.arrayobj.array_strides(context, builder, typ, value, attr)
numba.targets.arrayobj.getitem_array1d_intp(context, builder, sig, args)
numba.targets.arrayobj.getitem_array1d_slice(context, builder, sig, args)
numba.targets.arrayobj.getitem_array_tuple(context, builder, sig, args)
numba.targets.arrayobj.getitem_array_unituple(context, builder, sig, args)
numba.targets.arrayobj.getiter_array(context, builder, sig, args)
numba.targets.arrayobj.make_array(array_type)

Return the Structure representation of the given array_type (an instance of types.Array).

numba.targets.arrayobj.make_arrayiter_cls(iterator_type)

Return the Structure representation of the given iterator_type (an instance of types.ArrayIteratorType).

numba.targets.arrayobj.setitem_array1d(context, builder, sig, args)
numba.targets.arrayobj.setitem_array1d_slice(context, builder, sig, args)
numba.targets.arrayobj.setitem_array_tuple(context, builder, sig, args)
numba.targets.arrayobj.setitem_array_unituple(context, builder, sig, args)

numba.targets.base module

class numba.targets.base.BaseContext(typing_context)

Bases: object

Most objects are lowered as plain-old-data structure in the generated llvm. They are passed around by reference (a pointer to the structure). Only POD structure can life across function boundaries by copying the data.

add_exception(exc)
add_libs(libs)
call_class_method(builder, func, signature, args)
call_external_function(builder, callee, argtys, args)
call_function(builder, callee, resty, argtys, args, env=None)

Call the Numba-compiled callee, using the same calling convention as in get_function_type().

call_function_pointer(builder, funcptr, signature, args)
cast(builder, val, fromty, toty)
debug_print(builder, text)
declare_external_function(module, fndesc)
declare_function(module, fndesc)
finalize(func, fndesc)

Perform any necessary work to complete the compilation. An implementation of get_executable() should call finalize().

get_abi_sizeof(lty)
get_argument_type(ty)
get_argument_value(builder, ty, val)

Argument representation to local value representation

get_arguments(func)

Get the Python-level arguments of LLVM func. See get_function_type() for the calling convention.

get_attribute(val, typ, attr)
get_constant(ty, val)
get_constant_generic(builder, ty, val)

Return a LLVM constant representing value val of Numba type ty.

get_constant_null(ty)
get_constant_struct(builder, ty, val)
get_constant_undef(ty)
get_data_type(ty)

Get a data representation of the type that is safe for storage. Record data are stored as byte array.

Returns None if it is an opaque pointer

get_dummy_type()
get_dummy_value()
get_executable(func, fndesc)
get_external_function_type(fndesc)
get_function(fn, sig)
get_function_type(fndesc)

Get the implemented Function type for the high-level fndesc. Some parameters can be added or shuffled around. This is kept in sync with call_function() and get_arguments().

Returns: -2 for return none in native function;
-1 for failure with python exception set;
0 for success;

>0 for user error code.

Return value is passed by reference as the first argument.

Actual arguments starts at the 2rd argument position. Caller is responsible to allocate space for return value.

get_python_api(builder)
get_return_status(builder, code)
get_return_type(ty)
get_return_value(builder, ty, val)

Local value representation to return type representation

get_setattr(attr, sig)
get_struct_member_type(member_type)

Get the LLVM type for struct member of type member_type.

get_struct_member_value(builder, ty, val)

Local value representation to struct member representation

get_struct_type(struct)

Get the LLVM struct type for the given Structure class struct.

get_user_function(func)
get_value_as_argument(builder, ty, val)

Prepare local value representation as argument type representation

get_value_type(ty)
implement_pow_as_math_call = False
implement_powi_as_math_call = False
init()

For subclasses to add initializer

insert_attr_defn(defns)
insert_class(cls, attrs)
insert_const_string(mod, string)
insert_func_defn(defns)
insert_user_function(func, fndesc, libs=())
is_struct_type(ty)
is_true(builder, typ, val)
localized()

Returns a localized context that contains extra environment information

make_array(typ)
make_complex(typ)
make_constant_array(builder, typ, ary)
make_pair(first_type, second_type)

Create a heterogenous pair class parametered for the given types.

mangler = None
optimize(module)
optimize_function(func)

Perform function-level optimization. This may improve generated code and reduce memory usage.

Note: This is called at the end of lowering.

pack_value(builder, ty, value, ptr)

Pack data for array storage

pair_first(builder, val, ty)

Extract the first element of a heterogenous pair.

pair_second(builder, val, ty)

Extract the second element of a heterogenous pair.

print_string(builder, text)
return_errcode(builder, code)
return_errcode_propagate(builder, code)
return_exc(builder)
return_native_none(builder)
return_user_exc(builder, code)
return_value(builder, retval)
unpack_value(builder, ty, ptr)

Unpack data from array storage

class numba.targets.base.Overloads

Bases: object

append(impl)
find(sig)
class numba.targets.base.Status

Bases: tuple

Status(code, ok, err, exc, none)

code

Alias for field number 0

err

Alias for field number 2

exc

Alias for field number 3

none

Alias for field number 4

ok

Alias for field number 1

numba.targets.builtins module

class numba.targets.builtins.Complex128(context, builder, value=None, ref=None, cast_ref=False)

Bases: numba.cgutils.Structure

class numba.targets.builtins.Complex64(context, builder, value=None, ref=None, cast_ref=False)

Bases: numba.cgutils.Structure

class numba.targets.builtins.Slice(context, builder, value=None, ref=None, cast_ref=False)

Bases: numba.cgutils.Structure

numba.targets.builtins.caster(restype)
numba.targets.builtins.cls

alias of Complex128

numba.targets.builtins.complex128_imag_impl(context, builder, typ, value, attr)
numba.targets.builtins.complex128_power_impl(context, builder, sig, args)
numba.targets.builtins.complex128_real_impl(context, builder, typ, value, attr)
numba.targets.builtins.complex64_imag_impl(context, builder, typ, value, attr)
numba.targets.builtins.complex64_real_impl(context, builder, typ, value, attr)
numba.targets.builtins.complex_abs_impl(context, builder, sig, args)

abs(z) := hypot(z.real, z.imag)

numba.targets.builtins.complex_add_impl(context, builder, sig, args)
numba.targets.builtins.complex_div_impl(context, builder, sig, args)

z = c^2 + d^2 (a+bi)/(c+di) = (ac + bd) / z, (bc - ad) / z

numba.targets.builtins.complex_eq_impl(context, builder, sig, args)
numba.targets.builtins.complex_impl(context, builder, sig, args)
numba.targets.builtins.complex_mul_impl(context, builder, sig, args)

(a+bi)(c+di)=(ac-bd)+i(ad+bc)

numba.targets.builtins.complex_ne_impl(context, builder, sig, args)
numba.targets.builtins.complex_negate_impl(context, builder, sig, args)
numba.targets.builtins.complex_positive_impl(context, builder, sig, args)
numba.targets.builtins.complex_sub_impl(context, builder, sig, args)
numba.targets.builtins.float_impl(context, builder, sig, args)
numba.targets.builtins.get_complex_info(ty)
numba.targets.builtins.getitem_unituple(context, builder, sig, args)
numba.targets.builtins.getiter_unituple(context, builder, sig, args)
numba.targets.builtins.int_abs_impl(context, builder, sig, args)
numba.targets.builtins.int_add_impl(context, builder, sig, args)
numba.targets.builtins.int_and_impl(context, builder, sig, args)
numba.targets.builtins.int_ashr_impl(context, builder, sig, args)
numba.targets.builtins.int_divmod(context, builder, x, y)

Reference Objects/intobject.c xdivy = x / y; xmody = (long)(x - (unsigned long)xdivy * y); /* If the signs of x and y differ, and the remainder is non-0,

  • C89 doesn’t define whether xdivy is now the floor or the
  • ceiling of the infinitely precise quotient. We want the floor,
  • and we have it iff the remainder’s sign matches y’s.

*/

if (xmody && ((y ^ xmody) < 0) /* i.e. and signs differ */) {
xmody += y; –xdivy; assert(xmody && ((y ^ xmody) >= 0));

} *p_xdivy = xdivy; *p_xmody = xmody;

numba.targets.builtins.int_eq_impl(context, builder, sig, args)
numba.targets.builtins.int_impl(context, builder, sig, args)
numba.targets.builtins.int_invert_impl(context, builder, sig, args)
numba.targets.builtins.int_lshr_impl(context, builder, sig, args)
numba.targets.builtins.int_mul_impl(context, builder, sig, args)
numba.targets.builtins.int_ne_impl(context, builder, sig, args)
numba.targets.builtins.int_negate_impl(context, builder, sig, args)
numba.targets.builtins.int_or_impl(context, builder, sig, args)
numba.targets.builtins.int_positive_impl(context, builder, sig, args)
numba.targets.builtins.int_power_func_body(context, builder, x, y)
numba.targets.builtins.int_sdiv_impl(context, builder, sig, args)
numba.targets.builtins.int_sfloordiv_impl(context, builder, sig, args)
numba.targets.builtins.int_sge_impl(context, builder, sig, args)
numba.targets.builtins.int_sgt_impl(context, builder, sig, args)
numba.targets.builtins.int_shl_impl(context, builder, sig, args)
numba.targets.builtins.int_sign_impl(context, builder, sig, args)
numba.targets.builtins.int_sle_impl(context, builder, sig, args)
numba.targets.builtins.int_slt_impl(context, builder, sig, args)
numba.targets.builtins.int_spower_impl(context, builder, sig, args)
numba.targets.builtins.int_srem_impl(context, builder, sig, args)
numba.targets.builtins.int_struediv_impl(context, builder, sig, args)
numba.targets.builtins.int_sub_impl(context, builder, sig, args)
numba.targets.builtins.int_udiv_impl(context, builder, sig, args)
numba.targets.builtins.int_ufloordiv_impl(context, builder, sig, args)
numba.targets.builtins.int_uge_impl(context, builder, sig, args)
numba.targets.builtins.int_ugt_impl(context, builder, sig, args)
numba.targets.builtins.int_ule_impl(context, builder, sig, args)
numba.targets.builtins.int_ult_impl(context, builder, sig, args)
numba.targets.builtins.int_upower_impl(context, builder, sig, args)
numba.targets.builtins.int_urem_impl(context, builder, sig, args)
numba.targets.builtins.int_utruediv_impl(context, builder, sig, args)
numba.targets.builtins.int_xor_impl(context, builder, sig, args)
numba.targets.builtins.make_pair(first_type, second_type)
numba.targets.builtins.make_unituple_iter(tupiter)

Return the Structure representation of the given tupiter (an instance of types.UniTupleIter).

numba.targets.builtins.math_e_impl(context, builder, typ, value, attr)
numba.targets.builtins.math_pi_impl(context, builder, typ, value, attr)
numba.targets.builtins.max_impl(context, builder, sig, args)
numba.targets.builtins.min_impl(context, builder, sig, args)
numba.targets.builtins.number_as_bool_impl(context, builder, sig, args)
numba.targets.builtins.number_not_impl(context, builder, sig, args)
numba.targets.builtins.real_abs_impl(context, builder, sig, args)
numba.targets.builtins.real_add_impl(context, builder, sig, args)
numba.targets.builtins.real_div_impl(context, builder, sig, args)
numba.targets.builtins.real_divmod(context, builder, x, y)
numba.targets.builtins.real_divmod_func_body(context, builder, vx, wx)
numba.targets.builtins.real_eq_impl(context, builder, sig, args)
numba.targets.builtins.real_floordiv_impl(context, builder, sig, args)
numba.targets.builtins.real_ge_impl(context, builder, sig, args)
numba.targets.builtins.real_gt_impl(context, builder, sig, args)
numba.targets.builtins.real_le_impl(context, builder, sig, args)
numba.targets.builtins.real_lt_impl(context, builder, sig, args)
numba.targets.builtins.real_mod_impl(context, builder, sig, args)
numba.targets.builtins.real_mul_impl(context, builder, sig, args)
numba.targets.builtins.real_ne_impl(context, builder, sig, args)
numba.targets.builtins.real_negate_impl(context, builder, sig, args)
numba.targets.builtins.real_positive_impl(context, builder, sig, args)
numba.targets.builtins.real_power_impl(context, builder, sig, args)
numba.targets.builtins.real_sign_impl(context, builder, sig, args)
numba.targets.builtins.real_sub_impl(context, builder, sig, args)
numba.targets.builtins.round_impl_f32(context, builder, sig, args)
numba.targets.builtins.round_impl_f64(context, builder, sig, args)
numba.targets.builtins.slice0_empty_impl(context, builder, sig, args)
numba.targets.builtins.slice0_none_none_impl(context, builder, sig, args)
numba.targets.builtins.slice1_start_impl(context, builder, sig, args)
numba.targets.builtins.slice1_stop_impl(context, builder, sig, args)
numba.targets.builtins.slice2_impl(context, builder, sig, args)
numba.targets.builtins.slice3_impl(context, builder, sig, args)
numba.targets.builtins.uint_abs_impl(context, builder, sig, args)

numba.targets.cpu module

class numba.targets.cpu.CPUContext(typing_context)

Bases: numba.targets.base.BaseContext

Changes BaseContext calling convention

build_pass_manager()
call_function(builder, callee, resty, argtys, args, env=None)

Call the Numba-compiled callee, using the same calling convention as in get_function_type().

declare_function(module, fndesc)

Override parent to handle get_env_argument

dynamic_map_function(func)
finalize(func, fndesc)

Finalize the compilation. Called by get_executable().

  • Rewrite intrinsics
  • Fix div & rem instructions on 32bit platform
  • Optimize python API calls
get_abi_sizeof(lty)
get_arguments(func)

Override parent to handle enviroment argument Get the Python-level arguments of LLVM func. See get_function_type() for the calling convention.

get_env_argument(func)

Get the environment argument of LLVM func (which can be a declaration).

get_env_body(builder, envptr)

From the given envptr (a pointer to a _dynfunc.Environment object), get a EnvBody allowing structured access to environment fields.

get_env_from_closure(builder, clo)

From the pointer clo to a _dynfunc.Closure, get a pointer to the enclosed _dynfunc.Environment.

get_executable(func, fndesc, env)

(cfunc, fnptr)

  • cfunc

    callable function (Can be None)

  • fnptr

    callable function address

  • env

    an execution environment (from _dynfunc)

get_function_type(fndesc)

Get the implemented Function type for the high-level fndesc. Some parameters can be added or shuffled around. This is kept in sync with call_function() and get_arguments().

(Same return value convention as BaseContext target.) Returns: -2 for return none in native function;

-1 for failure with python exception set;
0 for success;

>0 for user error code.

Return value is passed by reference as the first argument.

The 2nd argument is a _dynfunc.Environment object. It MUST NOT be used if the function is in nopython mode.

Actual arguments starts at the 3rd argument position. Caller is responsible to allocate space for return value.

init()
map_math_functions()
map_numpy_math_functions()
optimize(module)
optimize_function(func)

Run O1 function passes

optimize_pythonapi(func)
prepare_for_call(func, fndesc, env)
class numba.targets.cpu.CPUTargetOptions

Bases: numba.targets.options.TargetOptions

OPTIONS = {'forceobj': <type 'bool'>, 'boundcheck': <type 'bool'>, 'nopython': <type 'bool'>, 'looplift': <type 'bool'>, 'wraparound': <type 'bool'>}
class numba.targets.cpu.ClosureBody(context, builder, value=None, ref=None, cast_ref=False)

Bases: numba.cgutils.Structure

class numba.targets.cpu.EnvBody(context, builder, value=None, ref=None, cast_ref=False)

Bases: numba.cgutils.Structure

numba.targets.cpu.remove_null_refct_call(bb)

Remove refct api calls to NULL pointer

numba.targets.cpu.remove_refct_calls(func)

Remove redundant incref/decref within on a per block basis

numba.targets.cpu.remove_refct_pairs(bb)

Remove incref decref pairs on the same variable

numba.targets.descriptors module

Target Descriptors

class numba.targets.descriptors.TargetDescriptor

Bases: object

numba.targets.imputils module

Utilities to simplify the boilerplate for native lowering.

class numba.targets.imputils.Registry

Bases: object

register(item)
register_attr(item)
numba.targets.imputils.call_getiter(context, builder, iterable_type, val)

Call the getiter() implementation for the given iterable_type of value val, and return the corresponding LLVM inst.

numba.targets.imputils.call_iternext(context, builder, iterator_type, val)

Call the iternext() implementation for the given iterator_type of value val, and return a convenience _IternextResult() object reflecting the results.

numba.targets.imputils.impl_attribute(ty, attr, rtype)
numba.targets.imputils.impl_attribute_generic(ty)
numba.targets.imputils.implement(func, *argtys)
numba.targets.imputils.iterator_impl(iterable_type, iterator_type)

Decorator a given class as implementing iterator_type (by providing an iternext() method).

numba.targets.imputils.iternext_impl(func)

Wrap the given iternext() implementation so that it gets passed an _IternextResult() object easing the returning of the iternext() result pair.

The wrapped function will be called with the following signature:
(context, builder, sig, args, iternext_result)
numba.targets.imputils.python_attr_impl(cls, attr, atyp)
numba.targets.imputils.user_function(func, fndesc, libs)

numba.targets.intrinsics module

LLVM pass that converts intrinsic into other math calls

class numba.targets.intrinsics.DivmodFixer

Bases: object

Fix 64-bit div/mod on 32-bit machines

I64 = <llvm.core.IntegerType object at 0x1073c9690>
NAMES = ('sdiv', 'udiv', 'srem', 'urem')
declare(module, fname)
run(module)
run_on_func(func)
class numba.targets.intrinsics.IntrinsicMapping(context, mapping=None, availintr=None)

Bases: object

apply_mapping(module)
run(module)
translate_intrinsic_to_cmath(module)
numba.targets.intrinsics.powi_as_pow(context, fn)

numba.targets.iterators module

Implementation of various iterable and iterator types.

numba.targets.iterators.iterator_getiter(context, builder, sig, args)
numba.targets.iterators.make_enumerate_cls(enum_type)

Return the Structure representation of the given enum_type (an instance of types.EnumerateType).

numba.targets.iterators.make_enumerate_object(context, builder, sig, args)
numba.targets.iterators.make_zip_cls(zip_type)

Return the Structure representation of the given zip_type (an instance of types.ZipType).

numba.targets.iterators.make_zip_object(context, builder, sig, args)

numba.targets.mathimpl module

Provide math calls that uses intrinsics or libc math functions.

numba.targets.mathimpl.atan2_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.atan2_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.atan2_s64_impl(context, builder, sig, args)
numba.targets.mathimpl.atan2_u64_impl(context, builder, sig, args)
numba.targets.mathimpl.degrees_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.degrees_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.hypot_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.hypot_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.hypot_s64_impl(context, builder, sig, args)
numba.targets.mathimpl.hypot_u64_impl(context, builder, sig, args)
numba.targets.mathimpl.isinf_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.isinf_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.isinf_s64_impl(context, builder, sig, args)
numba.targets.mathimpl.isinf_u64_impl(context, builder, sig, args)
numba.targets.mathimpl.isnan_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.isnan_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.isnan_s64_impl(context, builder, sig, args)
numba.targets.mathimpl.isnan_u64_impl(context, builder, sig, args)
numba.targets.mathimpl.radians_f32_impl(context, builder, sig, args)
numba.targets.mathimpl.radians_f64_impl(context, builder, sig, args)
numba.targets.mathimpl.unary_math_extern(fn, f32extern, f64extern, int_restype=False)

Register implementations of Python function fn using the external function named f32extern and f64extern (for float32 and float64 inputs, respectively). If int_restype is true, then the function’s return value should be integral, otherwise floating-point.

numba.targets.mathimpl.unary_math_int_impl(fn, f64impl)
numba.targets.mathimpl.unary_math_intr(fn, intrcode)

numba.targets.npyimpl module

class numba.targets.npyimpl.npy

This will be used as an index of the npy_* functions

acos = 'acos'
acosh = 'acosh'
asin = 'asin'
asinh = 'asinh'
atan = 'atan'
atan2 = 'atan2'
atanh = 'atanh'
ceil = 'ceil'
cos = 'cos'
cosh = 'cosh'
deg2rad = 'deg2rad'
exp = 'exp'
exp2 = 'exp2'
expm1 = 'expm1'
fabs = 'fabs'
floor = 'floor'
hypot = 'hypot'
log = 'log'
log10 = 'log10'
log1p = 'log1p'
log2 = 'log2'
logaddexp = 'logaddexp'
logaddexp2 = 'logaddexp2'
rad2deg = 'rad2deg'
rint = 'rint'
sin = 'sin'
sinh = 'sinh'
sqrt = 'sqrt'
tan = 'tan'
tanh = 'tanh'
trunc = 'trunc'
numba.targets.npyimpl.npy_math_extern(fn, fnty)
numba.targets.npyimpl.numpy_ufunc_kernel(context, builder, sig, args, kernel_class, explicit_output=True)
numba.targets.npyimpl.register_binary_ufunc_kernel(ufunc, kernel)
numba.targets.npyimpl.register_unary_ufunc_kernel(ufunc, kernel)

numba.targets.operatorimpl module

Definition of implementations for the operator module.

numba.targets.options module

Target Options

class numba.targets.options.TargetOptions

Bases: object

OPTIONS = {}
from_dict(dic)
classmethod parse_as_flags(flags, options)
set_flags(flags)

Provide default flags setting logic. Subclass can override.

numba.targets.printimpl module

This file implements print functionality for the CPU.

numba.targets.printimpl.int_print_impl(context, builder, sig, args)
numba.targets.printimpl.print_charseq(context, builder, sig, args)
numba.targets.printimpl.print_varargs(context, builder, sig, args)
numba.targets.printimpl.real_print_impl(context, builder, sig, args)

numba.targets.rangeobj module

Implementation of the range object for fixed-size integers.

numba.targets.rangeobj.make_range_impl(range_state_type, range_iter_type, int_type)
numba.targets.rangeobj.make_range_iterator(typ)

Return the Structure representation of the given typ (an instance of types.RangeIteratorType).

numba.targets.registry module

class numba.targets.registry.CPUOverloaded(py_func, locals={}, targetoptions={})

Bases: numba.dispatcher.Overloaded

targetdescr = <numba.targets.registry.CPUTarget object at 0x108223cd0>
class numba.targets.registry.CPUTarget

Bases: numba.targets.descriptors.TargetDescriptor

options

alias of CPUTargetOptions

target_context = <numba.targets.cpu.CPUContext object at 0x108223110>
typing_context = <numba.typing.context.Context object at 0x10816b890>
class numba.targets.registry.TargetRegistry(*args, **kws)

Bases: numba.utils.UniqueDict

ondemand:

A dictionary of target-name -> function, where function is executed the first time a target is used. It is used for deferred initialization for some targets (e.g. gpu).

Module contents