本文整理汇总了Python中numba.targets.imputils.impl_ret_new_ref函数的典型用法代码示例。如果您正苦于以下问题:Python impl_ret_new_ref函数的具体用法?Python impl_ret_new_ref怎么用?Python impl_ret_new_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了impl_ret_new_ref函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_attr_impl
def get_attr_impl(context, builder, typ, value, attr):
"""
Generic getattr() for @jitclass instances.
"""
if attr in typ.struct:
# It's a struct field
inst = context.make_helper(builder, typ, value=value)
data_pointer = inst.data
data = context.make_data_helper(builder, typ.get_data_type(),
ref=data_pointer)
return imputils.impl_ret_borrowed(context, builder,
typ.struct[attr],
getattr(data, _mangle_attr(attr)))
elif attr in typ.jitprops:
# It's a jitted property
getter = typ.jitprops[attr]['get']
sig = templates.signature(None, typ)
dispatcher = types.Dispatcher(getter)
sig = dispatcher.get_call_type(context.typing_context, [typ], {})
call = context.get_function(dispatcher, sig)
out = call(builder, [value])
_add_linking_libs(context, call)
return imputils.impl_ret_new_ref(context, builder, sig.return_type, out)
raise NotImplementedError('attribute {0!r} not implemented'.format(attr))
开发者ID:numba,项目名称:numba,代码行数:25,代码来源:base.py
示例2: imp
def imp(context, builder, sig, args):
instance_type = sig.args[0]
method = instance_type.jitmethods[attr]
disp_type = types.Dispatcher(method)
call = context.get_function(disp_type, sig)
out = call(builder, args)
return imputils.impl_ret_new_ref(context, builder,
sig.return_type, out)
开发者ID:digideskio,项目名称:numba,代码行数:8,代码来源:base.py
示例3: array_sinc
def array_sinc(context, builder, sig, args):
def array_sinc_impl(arr):
out = numpy.zeros_like(arr)
for index, val in numpy.ndenumerate(arr):
out[index] = numpy.sinc(val)
return out
res = context.compile_internal(builder, array_sinc_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:denfromufa,项目名称:numba,代码行数:8,代码来源:arraymath.py
示例4: codegen
def codegen(context, builder, signature, args):
# check that the return type is now defined
arrty = signature.return_type
assert arrty.is_precise()
shapes = unpack_tuple(builder, args[0])
# redirect implementation to np.empty
res = _empty_nd_impl(context, builder, arrty, shapes)
return impl_ret_new_ref(context, builder, arrty, res._getvalue())
开发者ID:cpcloud,项目名称:numba,代码行数:8,代码来源:ndarray.py
示例5: array_round
def array_round(context, builder, sig, args):
def array_round_impl(arr, decimals, out):
if arr.shape != out.shape:
raise ValueError("invalid output shape")
for index, val in numpy.ndenumerate(arr):
out[index] = numpy.round(val, decimals)
return out
res = context.compile_internal(builder, array_round_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:10,代码来源:arraymath.py
示例6: array_nonzero
def array_nonzero(context, builder, sig, args):
aryty = sig.args[0]
# Return type is a N-tuple of 1D C-contiguous arrays
retty = sig.return_type
outaryty = retty.dtype
ndim = aryty.ndim
nouts = retty.count
ary = make_array(aryty)(context, builder, args[0])
shape = cgutils.unpack_tuple(builder, ary.shape)
strides = cgutils.unpack_tuple(builder, ary.strides)
data = ary.data
layout = aryty.layout
# First count the number of non-zero elements
zero = context.get_constant(types.intp, 0)
one = context.get_constant(types.intp, 1)
count = cgutils.alloca_once_value(builder, zero)
with cgutils.loop_nest(builder, shape, zero.type) as indices:
ptr = cgutils.get_item_pointer2(builder, data, shape, strides,
layout, indices)
val = load_item(context, builder, aryty, ptr)
nz = context.is_true(builder, aryty.dtype, val)
with builder.if_then(nz):
builder.store(builder.add(builder.load(count), one), count)
# Then allocate output arrays of the right size
out_shape = (builder.load(count),)
outs = [_empty_nd_impl(context, builder, outaryty, out_shape)._getvalue()
for i in range(nouts)]
outarys = [make_array(outaryty)(context, builder, out) for out in outs]
out_datas = [out.data for out in outarys]
# And fill them up
index = cgutils.alloca_once_value(builder, zero)
with cgutils.loop_nest(builder, shape, zero.type) as indices:
ptr = cgutils.get_item_pointer2(builder, data, shape, strides,
layout, indices)
val = load_item(context, builder, aryty, ptr)
nz = context.is_true(builder, aryty.dtype, val)
with builder.if_then(nz):
# Store element indices in output arrays
if not indices:
# For a 0-d array, store 0 in the unique output array
indices = (zero,)
cur = builder.load(index)
for i in range(nouts):
ptr = cgutils.get_item_pointer2(builder, out_datas[i],
out_shape, (),
'C', [cur])
store_item(context, builder, outaryty, indices[i], ptr)
builder.store(builder.add(cur, one), index)
tup = context.make_tuple(builder, sig.return_type, outs)
return impl_ret_new_ref(context, builder, sig.return_type, tup)
开发者ID:denfromufa,项目名称:numba,代码行数:55,代码来源:arraymath.py
示例7: dot_2_mv
def dot_2_mv(context, builder, sig, args):
"""
np.dot(matrix, vector)
"""
def dot_impl(a, b):
m, n = a.shape
_n, = b.shape
out = np.empty((m, ), a.dtype)
return np.dot(a, b, out)
res = context.compile_internal(builder, dot_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:Alexhuszagh,项目名称:numba,代码行数:12,代码来源:linalg.py
示例8: make_zip_object
def make_zip_object(context, builder, sig, args):
zip_type = sig.return_type
assert len(args) == len(zip_type.source_types)
zipobj = context.make_helper(builder, zip_type)
for i, (arg, srcty) in enumerate(zip(args, sig.args)):
zipobj[i] = call_getiter(context, builder, srcty, arg)
res = zipobj._getvalue()
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:numba,项目名称:numba,代码行数:12,代码来源:iterators.py
示例9: build_list
def build_list(context, builder, list_type, items):
"""
Build a list of the given type, containing the given items.
"""
nitems = len(items)
inst = ListInstance.allocate(context, builder, list_type, nitems)
# Populate list
inst.size = context.get_constant(types.intp, nitems)
for i, val in enumerate(items):
inst.setitem(context.get_constant(types.intp, i), val)
return impl_ret_new_ref(context, builder, list_type, inst.value)
开发者ID:dhavide,项目名称:numba,代码行数:12,代码来源:listobj.py
示例10: dot_2_vm
def dot_2_vm(context, builder, sig, args):
"""
np.dot(vector, matrix)
"""
def dot_impl(a, b):
m, = a.shape
_m, n = b.shape
out = numpy.empty((n, ), a.dtype)
return numpy.dot(a, b, out)
res = context.compile_internal(builder, dot_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:nikete,项目名称:numba,代码行数:12,代码来源:arraymath.py
示例11: list_pop
def list_pop(context, builder, sig, args):
inst = ListInstance(context, builder, sig.args[0], args[0])
n = inst.size
cgutils.guard_zero(context, builder, n,
(IndexError, "pop from empty list"))
n = builder.sub(n, ir.Constant(n.type, 1))
res = inst.getitem(n)
inst.incref_value(res) # incref the pop'ed element
inst.clear_value(n) # clear the storage space
inst.resize(n)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:cpcloud,项目名称:numba,代码行数:12,代码来源:listobj.py
示例12: set_constructor
def set_constructor(context, builder, sig, args):
set_type = sig.return_type
items_type, = sig.args
items, = args
# If the argument has a len(), preallocate the set so as to
# avoid resizes.
n = call_len(context, builder, items_type, items)
inst = SetInstance.allocate(context, builder, set_type, n)
with for_iter(context, builder, items_type, items) as loop:
inst.add(loop.value)
return impl_ret_new_ref(context, builder, set_type, inst.value)
开发者ID:FedericoStra,项目名称:numba,代码行数:13,代码来源:setobj.py
示例13: array_angle_kwarg
def array_angle_kwarg(context, builder, sig, args):
arg = sig.args[0]
if isinstance(arg.dtype, types.Complex):
retty = arg.dtype.underlying_float
else:
retty = arg.dtype
def array_angle_impl(arr, deg=False):
out = numpy.zeros_like(arr, dtype=retty)
for index, val in numpy.ndenumerate(arr):
out[index] = numpy.angle(val, deg)
return out
res = context.compile_internal(builder, array_angle_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:nikete,项目名称:numba,代码行数:13,代码来源:arraymath.py
示例14: array_angle_kwarg
def array_angle_kwarg(context, builder, sig, args):
arg = sig.args[0]
ret_dtype = sig.return_type.dtype
def array_angle_impl(arr, deg):
out = numpy.zeros_like(arr, dtype=ret_dtype)
for index, val in numpy.ndenumerate(arr):
out[index] = numpy.angle(val, deg)
return out
if len(args) == 1:
args = args + (cgutils.false_bit,)
sig = signature(sig.return_type, *(sig.args + (types.boolean,)))
res = context.compile_internal(builder, array_angle_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:denfromufa,项目名称:numba,代码行数:16,代码来源:arraymath.py
示例15: array_cumprod
def array_cumprod(context, builder, sig, args):
scalar_dtype = sig.return_type.dtype
dtype = as_dtype(scalar_dtype)
def array_cumprod_impl(arr):
size = 1
for i in arr.shape:
size = size * i
out = numpy.empty(size, dtype)
c = 1
for idx, v in enumerate(arr.flat):
c *= v
out[idx] = c
return out
res = context.compile_internal(builder, array_cumprod_impl, sig, args, locals=dict(c=scalar_dtype))
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:17,代码来源:arraymath.py
示例16: any_where
def any_where(context, builder, sig, args):
cond = sig.args[0]
if isinstance(cond, types.Array):
return array_where(context, builder, sig, args)
def scalar_where_impl(cond, x, y):
"""
np.where(scalar, scalar, scalar): return a 0-dim array
"""
scal = x if cond else y
# This is the equivalent of numpy.full_like(scal, scal),
# for compatibility with Numpy < 1.8
arr = numpy.empty_like(scal)
arr[()] = scal
return arr
res = context.compile_internal(builder, scalar_where_impl, sig, args)
return impl_ret_new_ref(context, builder, sig.return_type, res)
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:18,代码来源:arraymath.py
示例17: list_add
def list_add(context, builder, sig, args):
a = ListInstance(context, builder, sig.args[0], args[0])
b = ListInstance(context, builder, sig.args[1], args[1])
a_size = a.size
b_size = b.size
nitems = builder.add(a_size, b_size)
dest = ListInstance.allocate(context, builder, sig.return_type, nitems)
dest.size = nitems
with cgutils.for_range(builder, a_size) as loop:
value = a.getitem(loop.index)
dest.setitem(loop.index, value)
with cgutils.for_range(builder, b_size) as loop:
value = b.getitem(loop.index)
dest.setitem(builder.add(loop.index, a_size), value)
return impl_ret_new_ref(context, builder, sig.return_type, dest.value)
开发者ID:gdementen,项目名称:numba,代码行数:18,代码来源:listobj.py
示例18: build_set
def build_set(context, builder, set_type, items):
"""
Build a set of the given type, containing the given items.
"""
nitems = len(items)
inst = SetInstance.allocate(context, builder, set_type, nitems)
# Populate set. Inlining the insertion code for each item would be very
# costly, instead we create a LLVM array and iterate over it.
array = cgutils.pack_array(builder, items)
array_ptr = cgutils.alloca_once_value(builder, array)
count = context.get_constant(types.intp, nitems)
with cgutils.for_range(builder, count) as loop:
item = builder.load(cgutils.gep(builder, array_ptr, 0, loop.index))
inst.add(item)
return impl_ret_new_ref(context, builder, set_type, inst.value)
开发者ID:FedericoStra,项目名称:numba,代码行数:18,代码来源:setobj.py
示例19: list_mul
def list_mul(context, builder, sig, args):
src = ListInstance(context, builder, sig.args[0], args[0])
src_size = src.size
mult = args[1]
zero = ir.Constant(mult.type, 0)
mult = builder.select(cgutils.is_neg_int(builder, mult), zero, mult)
nitems = builder.mul(mult, src_size)
dest = ListInstance.allocate(context, builder, sig.return_type, nitems)
dest.size = nitems
with cgutils.for_range_slice(builder, zero, nitems, src_size, inc=True) as (dest_offset, _):
with cgutils.for_range(builder, src_size) as loop:
value = src.getitem(loop.index)
dest.setitem(builder.add(loop.index, dest_offset), value)
return impl_ret_new_ref(context, builder, sig.return_type, dest.value)
开发者ID:dhavide,项目名称:numba,代码行数:18,代码来源:listobj.py
示例20: getslice_list
def getslice_list(context, builder, sig, args):
inst = ListInstance(context, builder, sig.args[0], args[0])
slice = slicing.Slice(context, builder, value=args[1])
cgutils.guard_invalid_slice(context, builder, slice)
inst.fix_slice(slice)
# Allocate result and populate it
result_size = slicing.get_slice_length(builder, slice)
result = ListInstance.allocate(context, builder, sig.return_type, result_size)
result.size = result_size
with cgutils.for_range_slice_generic(builder, slice.start, slice.stop, slice.step) as (pos_range, neg_range):
with pos_range as (idx, count):
value = inst.getitem(idx)
result.inititem(count, value)
with neg_range as (idx, count):
value = inst.getitem(idx)
result.inititem(count, value)
return impl_ret_new_ref(context, builder, sig.return_type, result.value)
开发者ID:maartenscholl,项目名称:numba,代码行数:19,代码来源:listobj.py
注:本文中的numba.targets.imputils.impl_ret_new_ref函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论