Example #1
0
def test_from_trf(thr, guiding_array):
    """
    Test the creation of ``PureParallel`` out of a transformation
    with various values of the guiding array.
    """

    N = 1000
    coeff = 3
    dtype = numpy.float32

    arr_t = Type(dtype, shape=N)
    trf = mul_param(arr_t, dtype)

    if guiding_array == 'input':
        arr = trf.input
    elif guiding_array == 'output':
        arr = trf.output
    elif guiding_array == 'none':
        arr = None

    p = PureParallel.from_trf(trf, guiding_array=arr)

    # The new PureParallel has to preserve the parameter list of the original transformation.
    assert list(p.signature.parameters.values()) == list(trf.signature.parameters.values())

    a = get_test_array_like(p.parameter.input)
    a_dev = thr.to_device(a)
    res_dev = thr.empty_like(p.parameter.output)

    pc = p.compile(thr)
    pc(res_dev, a_dev, coeff)

    assert diff_is_negligible(res_dev.get(), a * 3)
Example #2
0
def test_trf_with_guiding_output(thr):
    """
    Test the creation of ``PureParallel`` out of a transformation,
    with an output parameter as a guiding array.
    """

    N = 1000
    coeff = 3
    dtype = numpy.float32

    arr_t = Type(dtype, shape=N)
    trf = mul_param(arr_t, dtype)
    p = PureParallel.from_trf(trf, trf.output)

    # The new PureParallel has to preserve the parameter list of the original transformation.
    assert list(p.signature.parameters.values()) == list(trf.signature.parameters.values())

    a = get_test_array_like(p.parameter.input)
    a_dev = thr.to_device(a)
    res_dev = thr.empty_like(p.parameter.output)

    pc = p.compile(thr)
    pc(res_dev, a_dev, coeff)

    assert diff_is_negligible(res_dev.get(), a * 3)
Example #3
0
def test_mul_param(some_thr, any_dtype):

    input = get_test_array((1000,), any_dtype)
    p1 = get_test_array((1,), any_dtype)[0]
    p2 = get_test_array((1,), any_dtype)[0]
    input_dev = some_thr.to_device(input)
    output_dev = some_thr.empty_like(input_dev)

    test = get_test_computation(input_dev)
    scale = tr.mul_param(input_dev, any_dtype)

    test.parameter.input.connect(scale, scale.output, input_prime=scale.input, p1=scale.param)
    test.parameter.output.connect(scale, scale.input, output_prime=scale.output, p2=scale.param)
    testc = test.compile(some_thr)

    testc(output_dev, p1, input_dev, p2)
    assert diff_is_negligible(output_dev.get(), input * p1 * p2)
Example #4
0
def test_trivial(some_thr):
    """
    Checks that even if the FFT is trivial (problem size == 1),
    the transformations are still attached and executed.
    """
    dtype = numpy.complex64
    shape = (128, 1, 1, 128)
    axes = (1, 2)
    param = 4

    data = get_test_array(shape, dtype)
    data_dev = some_thr.to_device(data)
    res_dev = some_thr.empty_like(data_dev)

    fft = FFT(data_dev, axes=axes)
    scale = mul_param(data_dev, numpy.int32)
    fft.parameter.input.connect(scale, scale.output, input_prime=scale.input, param=scale.param)

    fftc = fft.compile(some_thr)
    fftc(res_dev, data_dev, param)
    assert diff_is_negligible(res_dev.get(), data * param)