Example #1
0
def _find_dtype_for_seq(space, elems_w, dtype):
    from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar
    for w_elem in elems_w:
        if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
            w_elem = w_elem.get_scalar_value()
        dtype = find_dtype_for_scalar(space, w_elem, dtype)
    return dtype
Example #2
0
def result_type(space, __args__):
    args_w, kw_w = __args__.unpack()
    if kw_w:
        raise oefmt(space.w_TypeError,
                    "result_type() takes no keyword arguments")
    if not args_w:
        raise oefmt(space.w_ValueError,
                    "at least one array or dtype is required")
    result = None
    for w_arg in args_w:
        if isinstance(w_arg, W_NDimArray):
            dtype = w_arg.get_dtype()
        elif isinstance(w_arg, W_GenericBox) or (
                space.isinstance_w(w_arg, space.w_int)
                or space.isinstance_w(w_arg, space.w_float)
                or space.isinstance_w(w_arg, space.w_complex)
                or space.isinstance_w(w_arg, space.w_long)
                or space.isinstance_w(w_arg, space.w_bool)):
            dtype = ufuncs.find_dtype_for_scalar(space, w_arg)
        else:
            dtype = space.interp_w(
                descriptor.W_Dtype,
                space.call_function(space.gettypefor(descriptor.W_Dtype),
                                    w_arg))
        result = ufuncs.find_binop_result_dtype(space, result, dtype)
    return result
Example #3
0
def _find_dtype_for_seq(space, elems_w, dtype):
    from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar
    for w_elem in elems_w:
        if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
            w_elem = w_elem.get_scalar_value()
        dtype = find_dtype_for_scalar(space, w_elem, dtype)
    return dtype
Example #4
0
def find_dtype_for_seq(space, elems_w, dtype):
    from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar
    if len(elems_w) == 1:
        w_elem = elems_w[0]
        if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
            w_elem = w_elem.get_scalar_value()
        return find_dtype_for_scalar(space, w_elem, dtype)
    return _find_dtype_for_seq(space, elems_w, dtype)
Example #5
0
def find_dtype_for_seq(space, elems_w, dtype):
    from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar
    if len(elems_w) == 1:
        w_elem = elems_w[0]
        if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
            w_elem = w_elem.get_scalar_value()
        return find_dtype_for_scalar(space, w_elem, dtype)
    return _find_dtype_for_seq(space, elems_w, dtype)
Example #6
0
def result_type(space, __args__):
    args_w, kw_w = __args__.unpack()
    if kw_w:
        raise oefmt(space.w_TypeError, "result_type() takes no keyword arguments")
    if not args_w:
        raise oefmt(space.w_ValueError, "at least one array or dtype is required")
    result = None
    for w_arg in args_w:
        if isinstance(w_arg, W_NDimArray):
            dtype = w_arg.get_dtype()
        elif isinstance(w_arg, W_GenericBox) or (
                space.isinstance_w(w_arg, space.w_int) or
                space.isinstance_w(w_arg, space.w_float) or
                space.isinstance_w(w_arg, space.w_complex) or
                space.isinstance_w(w_arg, space.w_long) or
                space.isinstance_w(w_arg, space.w_bool)):
            dtype = ufuncs.find_dtype_for_scalar(space, w_arg)
        else:
            dtype = space.interp_w(descriptor.W_Dtype,
                space.call_function(space.gettypefor(descriptor.W_Dtype), w_arg))
        result = ufuncs.find_binop_result_dtype(space, result, dtype)
    return result