Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_nan_overload(val):
if isinstance(val, (types.NPDatetime, types.NPTimedelta)):
nat = val('NaT')
return lambda val: nat
# TODO: other types
return lambda val: np.nan
pre_nodes.append(node)
return d_var
# TODO: stararg needs special handling?
args = numba.typing.fold_arguments(
pysig, args, kws, normal_handler, default_handler,
normal_handler)
arg_typs = tuple(self.typemap[v.name] for v in args)
if const:
new_args = []
for i, arg in enumerate(args):
val = guard(find_const, self.func_ir, arg)
if val:
new_args.append(types.literal(val))
else:
new_args.append(arg_typs[i])
arg_typs = tuple(new_args)
return ReplaceFunc(func, arg_typs, args, glbls, pre_nodes)
def _match(formal, actual):
if formal == actual:
# formal argument matches actual arguments
return True
elif types.Any == formal:
# formal argument is any
return True
elif (isinstance(formal, types.Kind) and
isinstance(actual, formal.of)):
# formal argument is a kind and the actual argument
# is of that kind
return True
value.value)
else:
const = self.context.get_constant(ty, value.value)
return const
elif isinstance(value, ir.Expr):
return self.lower_expr(ty, value)
elif isinstance(value, ir.Var):
val = self.loadvar(value.name)
oty = self.typeof(value.name)
return self.context.cast(self.builder, val, oty, ty)
elif isinstance(value, ir.Global):
if (isinstance(ty, types.Dummy) or
isinstance(ty, types.Module) or
isinstance(ty, types.Function) or
isinstance(ty, types.Dispatcher)):
return self.context.get_dummy_value()
elif ty == types.boolean:
return self.context.get_constant(ty, value.value)
elif isinstance(ty, types.Array):
return self.context.make_constant_array(self.builder, ty,
value.value)
elif self.context.is_struct_type(ty):
return self.context.get_constant_struct(self.builder, ty,
value.value)
elif ty in types.number_domain:
"""
# We've matched a subexpression assignment to an
# array variable. Now see if the expression is an
# array expression.
expr_op = expr.op
array_assigns = self.array_assigns
if ((expr_op in ('unary', 'binop')) and (
expr.fn in npydecl.supported_array_operators)):
# It is an array operator that maps to a ufunc.
array_assigns[target_name] = instr
elif ((expr_op == 'call') and (expr.func.name in self.typemap)):
# It could be a match for a known ufunc call.
func_type = self.typemap[expr.func.name]
if isinstance(func_type, types.Function):
func_key = func_type.typing_key
if _is_ufunc(func_key):
# If so, check whether an explicit output is passed.
if not self._has_explicit_output(expr, func_key):
# If not, match it as a (sub)expression.
array_assigns[target_name] = instr
def ol_bar_scalar(x):
# An overload that will inline based on a cost model, it only applies to
# scalar values in the numerical domain as per the type guard on Number
if isinstance(x, types.Number):
def impl(x):
return x + 1
return impl
@unbox(types.PyObject)
@unbox(types.Object)
def unbox_pyobject(typ, obj, c):
return NativeValue(obj)
def normalize_index(index):
if isinstance(index, types.UniTuple):
if index.dtype in types.integer_domain:
return types.UniTuple(types.intp, len(index))
elif index.dtype == types.slice3_type:
return index
elif isinstance(index, types.Tuple):
for ty in index:
if (ty not in types.integer_domain and
ty not in types.real_domain and
ty != types.slice3_type):
return
return index
elif index == types.slice3_type:
return types.slice3_type
class Hsa_mem_fence(ConcreteTemplate):
key = roc.mem_fence
cases = [signature(types.void, types.uint32)]
@intrinsic
class Hsa_wavebarrier(ConcreteTemplate):
key = roc.wavebarrier
cases = [signature(types.void)]
@intrinsic
class Hsa_activelanepermute_wavewidth(ConcreteTemplate):
key = roc.activelanepermute_wavewidth
# parameter: src, laneid, identity, useidentity
cases = [signature(ty, ty, types.uint32, ty, types.bool_)
for ty in (types.integer_domain|types.real_domain)]
class _Hsa_ds_permuting(ConcreteTemplate):
# parameter: index, source
cases = [signature(types.int32, types.int32, types.int32),
signature(types.int32, types.int64, types.int32),
signature(types.float32, types.int32, types.float32),
signature(types.float32, types.int64, types.float32)]
unsafe_casting = False
@intrinsic
class Hsa_ds_permute(_Hsa_ds_permuting):
key = roc.ds_permute
def adapt_argument(ctx, ty):
if isinstance(ty, types.Array):
# Handle array
yield lc.Type.pointer(ctx.get_value_type(ty.dtype),
addr_space=SPIR_GLOBAL_ADDRSPACE)
for i in range(2 * ty.ndim): # shape + strides
yield ctx.get_value_type(types.intp)
elif ty in types.complex_domain:
# Handle complex number
dtype = types.float32 if ty == types.complex64 else types.float64
for _ in range(2):
yield ctx.get_value_type(dtype)
else:
yield ctx.get_vaue_type(ty)