def _getsetitem_gen(getset): _dunder_meth = "__%s__" % getset op = getattr(operator, getset) @templates.infer_global(op) class GetSetItem(templates.AbstractTemplate): def generic(self, args, kws): instance = args[0] if isinstance(instance, types.ClassInstanceType) and \ _dunder_meth in instance.jitmethods: meth = instance.jitmethods[_dunder_meth] disp_type = types.Dispatcher(meth) sig = disp_type.get_call_type(self.context, args, kws) return sig # lower both {g,s}etitem and __{g,s}etitem__ to catch the calls # from python and numba imputils.lower_builtin((types.ClassInstanceType, _dunder_meth), types.ClassInstanceType, types.VarArg(types.Any))(get_imp()) imputils.lower_builtin(op, types.ClassInstanceType, types.VarArg(types.Any))(get_imp())
def generic(self, args, kws): """ Type the intrinsic by the arguments. """ from numba.targets.imputils import lower_builtin cache_key = self.context, args, tuple(kws.items()) try: return self._impl_cache[cache_key] except KeyError: result = self._definition_func(self.context, *args, **kws) if result is None: return [sig, imp] = result pysig = utils.pysignature(self._definition_func) # omit context argument from user function parameters = list(pysig.parameters.values())[1:] sig.pysig = pysig.replace(parameters=parameters) self._impl_cache[cache_key] = sig self._overload_cache[sig.args] = imp # register the lowering lower_builtin(imp, *sig.args)(imp) return sig
timedelta_eq_timedelta_impl = _create_timedelta_comparison_impl( lc.ICMP_EQ, cgutils.false_bit) timedelta_ne_timedelta_impl = _create_timedelta_comparison_impl( lc.ICMP_NE, cgutils.true_bit) timedelta_lt_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SLT) timedelta_le_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SLE) timedelta_gt_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SGT) timedelta_ge_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SGE) for op, func in [('==', timedelta_eq_timedelta_impl), ('!=', timedelta_ne_timedelta_impl), ('<', timedelta_lt_timedelta_impl), ('<=', timedelta_le_timedelta_impl), ('>', timedelta_gt_timedelta_impl), ('>=', timedelta_ge_timedelta_impl)]: lower_builtin(op, *TIMEDELTA_BINOP_SIG)(func) # Arithmetic on datetime64 def is_leap_year(builder, year_val): """ Return a predicate indicating whether *year_val* (offset by 1970) is a leap year. """ actual_year = builder.add(year_val, Constant.int(DATETIME64, 1970)) multiple_of_4 = cgutils.is_null( builder, builder.and_(actual_year, Constant.int(DATETIME64, 3))) not_multiple_of_100 = cgutils.is_not_null( builder, builder.srem(actual_year, Constant.int(DATETIME64, 100))) multiple_of_400 = cgutils.is_null(
timedelta_eq_timedelta_impl = _create_timedelta_comparison_impl(lc.ICMP_EQ, cgutils.false_bit) timedelta_ne_timedelta_impl = _create_timedelta_comparison_impl(lc.ICMP_NE, cgutils.true_bit) timedelta_lt_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SLT) timedelta_le_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SLE) timedelta_gt_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SGT) timedelta_ge_timedelta_impl = _create_timedelta_ordering_impl(lc.ICMP_SGE) for op, func in [('==', timedelta_eq_timedelta_impl), ('!=', timedelta_ne_timedelta_impl), ('<', timedelta_lt_timedelta_impl), ('<=', timedelta_le_timedelta_impl), ('>', timedelta_gt_timedelta_impl), ('>=', timedelta_ge_timedelta_impl)]: lower_builtin(op, *TIMEDELTA_BINOP_SIG)(func) # Arithmetic on datetime64 def is_leap_year(builder, year_val): """ Return a predicate indicating whether *year_val* (offset by 1970) is a leap year. """ actual_year = builder.add(year_val, Constant.int(DATETIME64, 1970)) multiple_of_4 = cgutils.is_null( builder, builder.and_(actual_year, Constant.int(DATETIME64, 3))) not_multiple_of_100 = cgutils.is_not_null( builder, builder.srem(actual_year, Constant.int(DATETIME64, 100))) multiple_of_400 = cgutils.is_null(