예제 #1
0
 def _promote_numeric(self, typ):
     coercer = expressions.coercer_from_dtype(typ)
     if isinstance(typ, tarray) and not isinstance(self.dtype, tarray):
         return coercer.ec.coerce(self)
     elif isinstance(typ, tndarray) and not isinstance(self.dtype, tndarray):
         return coercer.ec.coerce(self)
     else:
         return coercer.coerce(self)
예제 #2
0
 def _promote_numeric(self, typ):
     coercer = expressions.coercer_from_dtype(typ)
     if isinstance(typ, tarray) and not isinstance(self.dtype, tarray):
         return coercer.ec.coerce(self)
     elif isinstance(typ, tndarray) and not isinstance(self.dtype, tndarray):
         return coercer.ec.coerce(self)
     else:
         return coercer.coerce(self)
예제 #3
0
def unify_exprs(*exprs: 'Expression') -> Tuple:
    assert len(exprs) > 0
    types = {e.dtype for e in exprs}

    # all types are the same
    if len(types) == 1:
        return exprs + (True, )

    for t in types:
        c = expressions.coercer_from_dtype(t)
        if all(c.can_coerce(e.dtype) for e in exprs):
            return tuple([c.coerce(e) for e in exprs]) + (True, )

    # cannot coerce all types to the same type
    return exprs + (False, )
예제 #4
0
def unify_exprs(*exprs: 'Expression') -> Tuple:
    assert len(exprs) > 0
    types = {e.dtype for e in exprs}

    # all types are the same
    if len(types) == 1:
        return exprs + (True,)

    for t in types:
        c = expressions.coercer_from_dtype(t)
        if all(c.can_coerce(e.dtype) for e in exprs):
            return tuple([c.coerce(e) for e in exprs]) + (True,)

    # cannot coerce all types to the same type
    return exprs + (False,)