def comparator_helper(op_str, left_var, right_var, negated=False):
    if (isinstance(left_var, VarTypeTemplate)):
        check_legal_cmp(left_var, op_str, right_var)
        op_str = types.unliteral(op_str)
        # print("AAAA", op_str)
        if (not isinstance(right_var, VarTypeTemplate)):
            # print("POOP")
            right_var_type = types.unliteral(right_var)

            # ctor = gen_pterm_ctor_alpha(left_var, op_str, right_var_type)
            # print("POOP")

            def impl(left_var, right_var):
                pt = PTerm(left_var, op_str, right_var)
                lbv = cast_structref(GenericVarType, left_var)
                return pt_to_cond(pt, lbv, None, negated)
        else:
            # ctor = gen_pterm_ctor_beta(left_var, op_str, right_var)
            def impl(left_var, right_var):
                pt = PTerm(left_var, op_str, right_var)
                lbv = cast_structref(GenericVarType, left_var)
                rbv = cast_structref(GenericVarType, right_var)
                return pt_to_cond(pt, lbv, rbv, negated)

            # return var_cmp_beta

        return impl
Beispiel #2
0
def _create_dataset_typer(args, kws):
    kwargs = dict(kws)
    name = args[0] if len(args) > 0 else types.unliteral(kwargs['name'])
    shape = args[1] if len(args) > 1 else types.unliteral(kwargs['shape'])
    dtype = args[2] if len(args) > 2 else types.unliteral(kwargs['dtype'])
    def create_dset_stub(name, shape, dtype):
        pass
    pysig = numba.utils.pysignature(create_dset_stub)
    return signature(h5dataset_type, name, shape, dtype).replace(pysig=pysig)
Beispiel #3
0
 def _cmp_helper(self,op_str,other,negate):
     check_legal_cmp(self, op_str, other)
     opt_str = types.literal(types.unliteral(op_str))
     if(not isinstance(other,(VarTypeTemplate,Var))):
         return var_cmp_alpha(self,op_str,other, negate)
     else:
         return var_cmp_beta(self,op_str,other, negate)
Beispiel #4
0
def var_cmp_alpha(left_var, op_str, right_var,negated):
    from cre.condition_node import pt_to_cond, gen_pterm_ctor_alpha, gen_pterm_ctor_beta
    right_var_type = types.unliteral(types.literal(right_var))
    ctor = gen_pterm_ctor_alpha(left_var._numba_type_, op_str, right_var_type)
    pt = ctor(left_var, op_str, right_var)
    lbv = cast_structref(GenericVarType,left_var)
    return pt_to_cond(pt, lbv, None, negated)
Beispiel #5
0
    def unify_pairs(self, first, second):
        """
        Try to unify the two given types.  A third type is returned,
        or None in case of failure.
        """
        if first == second:
            return first

        if first is types.undefined:
            return second
        elif second is types.undefined:
            return first

        # Types with special unification rules
        unified = first.unify(self, second)
        if unified is not None:
            return unified

        unified = second.unify(self, first)
        if unified is not None:
            return unified

        # Other types with simple conversion rules
        conv = self.can_convert(fromty=first, toty=second)
        if conv is not None and conv <= Conversion.safe:
            # Can convert from first to second
            return second

        conv = self.can_convert(fromty=second, toty=first)
        if conv is not None and conv <= Conversion.safe:
            # Can convert from second to first
            return first

        if isinstance(first, types.Literal) or isinstance(
                second, types.Literal):
            first = types.unliteral(first)
            second = types.unliteral(second)
            return self.unify_pairs(first, second)

        # Cannot unify
        return None
Beispiel #6
0
def as_dtype(nbtype):
    """
    Return a Pandas *dtype* instance corresponding to the given Numba type.
    NotImplementedError is raised if no correspondence is known.
    """
    nbtype = types.unliteral(nbtype)
    if isinstance(nbtype, CategoricalDtypeType):
        return pd.CategoricalDtype(categories=nbtype.categories,
                                   ordered=nbtype.ordered)

    raise NotImplementedError("%r cannot be represented as a Pandas dtype" %
                              (nbtype, ))
Beispiel #7
0
    def unify_pairs(self, first, second):
        """
        Try to unify the two given types.  A third type is returned,
        or None in case of failure.
        """
        if first == second:
            return first

        if first is types.undefined:
            return second
        elif second is types.undefined:
            return first

        # Types with special unification rules
        unified = first.unify(self, second)
        if unified is not None:
            return unified

        unified = second.unify(self, first)
        if unified is not None:
            return unified

        # Other types with simple conversion rules
        conv = self.can_convert(fromty=first, toty=second)
        if conv is not None and conv <= Conversion.safe:
            # Can convert from first to second
            return second

        conv = self.can_convert(fromty=second, toty=first)
        if conv is not None and conv <= Conversion.safe:
            # Can convert from second to first
            return first

        if isinstance(first, types.Literal) or isinstance(second, types.Literal):
            first = types.unliteral(first)
            second = types.unliteral(second)
            return self.unify_pairs(first, second)

        # Cannot unify
        return None
Beispiel #8
0
 def _resolve_builtin_function_type(self, func, args, kws):
     # NOTE: we should reduce usage of this
     if func in self._functions:
         # Note: Duplicating code with types.Function.get_call_type().
         #       *defns* are CallTemplates.
         defns = self._functions[func]
         for defn in defns:
             for support_literals in [True, False]:
                 if support_literals:
                     res = defn.apply(args, kws)
                 else:
                     fixedargs = [types.unliteral(a) for a in args]
                     res = defn.apply(fixedargs, kws)
                 if res is not None:
                     return res
Beispiel #9
0
 def generic(self, args, kws):
     assert not kws
     assert len(args) == 1
     column = types.unliteral(args[0])
     ret_typ = column
     if (isinstance(column, types.List)
             and (isinstance(column.dtype, types.Number)
                  or column.dtype == types.boolean)):
         ret_typ = types.Array(column.dtype, 1, 'C')
     if (isinstance(column, types.List)
             and (column.dtype == string_type
                  or isinstance(column.dtype, types.Optional)
                  and column.dtype.type == string_type)):
         ret_typ = string_array_type
     if isinstance(column, SeriesType):
         ret_typ = column.data
     # TODO: add other types
     return signature(ret_typ, column)
Beispiel #10
0
    def resolve_getattr(self, typ, attr):
        """
        Resolve getting the attribute *attr* (a string) on the Numba type.
        The attribute's type is returned, or None if resolution failed.
        """
        def core(typ):
            out = self.find_matching_getattr_template(typ, attr)
            if out:
                return out['return_type']

        out = core(typ)
        if out is not None:
            return out

        # Try again without literals
        out = core(types.unliteral(typ))
        if out is not None:
            return out

        if isinstance(typ, types.Module):
            attrty = self.resolve_module_constants(typ, attr)
            if attrty is not None:
                return attrty
Beispiel #11
0
    def resolve_getattr(self, typ, attr):
        """
        Resolve getting the attribute *attr* (a string) on the Numba type.
        The attribute's type is returned, or None if resolution failed.
        """
        def core(typ):
            for attrinfo in self._get_attribute_templates(typ):
                ret = attrinfo.resolve(typ, attr)
                if ret is not None:
                    return ret

        out = core(typ)
        if out is not None:
            return out

        # Try again without literals
        out = core(types.unliteral(typ))
        if out is not None:
            return out

        if isinstance(typ, types.Module):
            attrty = self.resolve_module_constants(typ, attr)
            if attrty is not None:
                return attrty
Beispiel #12
0
 def generic(self, args, kws):
     assert not kws
     assert len(args) == 2
     return signature(types.intp, args[0], types.unliteral(args[1]))
Beispiel #13
0
def unliteral_all(args):
    return tuple(types.unliteral(a) for a in args)
Beispiel #14
0
 def resolve_split(self, dict, args, kws):
     assert not kws
     assert len(args) == 1
     return signature(types.List(string_type), types.unliteral(args[0]))
Beispiel #15
0
 def preprocess_fields(self, fields):
     return tuple((name, types.unliteral(typ)) for name, typ in fields)