Exemplo n.º 1
0
def generate_dtypes(out_code, in_codes):
    test_dtype = lambda idx: dict(
        i=numpy.int32, f=numpy.float32, c=numpy.complex64)[idx]
    in_dtypes = list(map(test_dtype, in_codes))
    out_dtype = dtypes.result_type(
        *in_dtypes) if out_code == 'auto' else test_dtype(out_code)

    if not any(map(dtypes.is_double, in_dtypes)):
        # numpy thinks that int32 * float32 == float64,
        # but we still need to run this test on older videocards
        if dtypes.is_complex(out_dtype):
            out_dtype = numpy.complex64
        elif dtypes.is_real(out_dtype):
            out_dtype = numpy.float32

    return out_dtype, in_dtypes
Exemplo n.º 2
0
def get_test_array(shape,
                   dtype,
                   strides=None,
                   offset=0,
                   no_zeros=False,
                   high=None):
    shape = wrap_in_tuple(shape)
    dtype = dtypes.normalize_type(dtype)

    if offset != 0:
        raise NotImplementedError()

    if dtype.names is not None:
        result = numpy.empty(shape, dtype)
        for name in dtype.names:
            result[name] = get_test_array(shape,
                                          dtype[name],
                                          no_zeros=no_zeros,
                                          high=high)
    else:
        if dtypes.is_integer(dtype):
            low = 1 if no_zeros else 0
            if high is None:
                high = 100  # will work even with signed chars
            get_arr = lambda: numpy.random.randint(low, high, shape).astype(
                dtype)
        else:
            low = 0.01 if no_zeros else 0
            if high is None:
                high = 1.0
            get_arr = lambda: numpy.random.uniform(low, high, shape).astype(
                dtype)

        if dtypes.is_complex(dtype):
            result = get_arr() + 1j * get_arr()
        else:
            result = get_arr()

    if strides is not None:
        result = as_strided(result, result.shape, strides)

    return result
Exemplo n.º 3
0
 def reference_mul(*args):
     res = prod(args)
     if not dtypes.is_complex(out_dtype) and dtypes.is_complex(res.dtype):
         res = res.real
     return res.astype(out_dtype)
Exemplo n.º 4
0
 def reference_add(*args):
     res = sum(args)
     if not dtypes.is_complex(out_dtype) and dtypes.is_complex(res.dtype):
         res = res.real
     return res.astype(out_dtype)
Exemplo n.º 5
0
def test_is_complex():
    assert dtypes.is_complex(numpy.complex64)
    assert dtypes.is_complex(numpy.complex128)
    assert not dtypes.is_complex(numpy.float64)