Ejemplo n.º 1
0
def test_scale_param(some_ctx, any_dtype):

    input = get_test_array((1000,), any_dtype)
    p1 = get_test_array((1,), any_dtype)
    p2 = get_test_array((1,), any_dtype)
    input_dev = some_ctx.to_device(input)
    output_dev = some_ctx.empty_like(input_dev)

    test = TestComputation(some_ctx)
    test.connect(tr.scale_param(), 'input', ['input_prime'], ['p1'])
    test.connect(tr.scale_param(), 'output', ['output_prime'], ['p2'])
    test.prepare_for(output_dev, input_dev, p1[0], p2[0])

    test(output_dev, input_dev, p1[0], p2[0])
    assert diff_is_negligible(output_dev.get(), input * p1[0] * p2[0])
Ejemplo n.º 2
0
def test_scale_param(some_ctx, any_dtype):

    input = get_test_array((1000, ), any_dtype)
    p1 = get_test_array((1, ), any_dtype)
    p2 = get_test_array((1, ), any_dtype)
    input_dev = some_ctx.to_device(input)
    output_dev = some_ctx.empty_like(input_dev)

    test = TestComputation(some_ctx)
    test.connect(tr.scale_param(), 'input', ['input_prime'], ['p1'])
    test.connect(tr.scale_param(), 'output', ['output_prime'], ['p2'])
    test.prepare_for(output_dev, input_dev, p1[0], p2[0])

    test(output_dev, input_dev, p1[0], p2[0])
    assert diff_is_negligible(output_dev.get(), input * p1[0] * p2[0])
Ejemplo n.º 3
0
def test_scalar_fixed_type(some_ctx):
    """
    Regression test for the bug when explicitly specified type for a scalar argument
    was ignored, and the result of result numpy.min_scalar_type() was used instead.
    """

    N = 1024
    p = numpy.int32(2)
    coeff = numpy.int32(1)

    test = Dummy(some_ctx)
    A = some_ctx.allocate(N, numpy.int32)
    B = some_ctx.allocate(N, numpy.int32)
    C = some_ctx.allocate(N, numpy.int32)
    D = some_ctx.allocate(N, numpy.int32)

    test.connect(transformations.scale_param(), 'A', ['A_prime'], ['param'])
    test.prepare_for(C, D, A, B, coeff, p)
    assert test.signature_str() == (
        "(array, int32, (1024,)) C, "
        "(array, int32, (1024,)) D, "
        "(array, int32, (1024,)) A_prime, "
        "(array, int32, (1024,)) B, "
        "(scalar, int32) coeff, "
        "(scalar, int32) param")
Ejemplo n.º 4
0
def test_trivial(some_ctx):
    """
    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_ctx.to_device(data)
    res_dev = some_ctx.empty_like(data_dev)

    fft = FFT(some_ctx)
    fft.connect(scale_param(), 'input', ['input_prime'], ['param'])
    fft.prepare_for(res_dev, data_dev, None, param, axes=axes)

    fft(res_dev, data_dev, -1, param)
    assert diff_is_negligible(res_dev.get(), data * param)
Ejemplo n.º 5
0
def test_trivial(some_ctx):
    """
    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_ctx.to_device(data)
    res_dev = some_ctx.empty_like(data_dev)

    fft = FFT(some_ctx)
    fft.connect(scale_param(), 'input', ['input_prime'], ['param'])
    fft.prepare_for(res_dev, data_dev, None, param, axes=axes)

    fft(res_dev, data_dev, -1, param)
    assert diff_is_negligible(res_dev.get(), data * param)