Example #1
0
def cast(arr_t, dtype):
    """
    Returns a typecast transformation of ``arr_t`` to ``dtype``
    (1 output, 1 input): ``output = cast[dtype](input)``.
    """
    dest = Type.from_value(arr_t).with_dtype(dtype)
    return Transformation(
        [Parameter('output', Annotation(dest, 'o')),
        Parameter('input', Annotation(arr_t, 'i'))],
        "${output.store_same}(${cast}(${input.load_same}));",
        render_kwds=dict(cast=functions.cast(dtype, arr_t.dtype)))
Example #2
0
def tr_2_to_1(arr, scalar):
    return Transformation(
        [Parameter('o1', Annotation(arr, 'o')),
        Parameter('i1', Annotation(arr, 'i')),
        Parameter('i2', Annotation(arr, 'i')),
        Parameter('s1', Annotation(scalar))],
        """
        ${o1.ctype} t = ${mul}(${cast}(${s1}), ${i1.load_same});
        ${o1.store_same}(t + ${i2.load_same});
        """,
        render_kwds= dict(
            mul=functions.mul(arr.dtype, arr.dtype),
            cast=functions.cast(arr.dtype, scalar.dtype)))
Example #3
0
def cast(arr_t, dtype):
    """
    Returns a typecast transformation of ``arr_t`` to ``dtype``
    (1 output, 1 input): ``output = cast[dtype](input)``.
    """
    dest = Type.from_value(arr_t).with_dtype(dtype)
    return Transformation(
        [
            Parameter('output', Annotation(dest, 'o')),
            Parameter('input', Annotation(arr_t, 'i'))
        ],
        "${output.store_same}(${cast}(${input.load_same}));",
        render_kwds=dict(cast=functions.cast(dtype, arr_t.dtype)))
Example #4
0
def test_cast(thr, out_code, in_codes):
    out_dtype, in_dtypes = generate_dtypes(out_code, in_codes)
    check_func(thr, functions.cast(out_dtype, in_dtypes[0]),
               dtypes.cast(out_dtype), out_dtype, in_dtypes)
Example #5
0
def test_cast(thr, out_code, in_codes):
    out_dtype, in_dtypes = generate_dtypes(out_code, in_codes)
    check_func(
        thr, functions.cast(out_dtype, in_dtypes[0]),
        dtypes.cast(out_dtype), out_dtype, in_dtypes)