Esempio n. 1
0
def check_errors_first_order(thr, mshape, batch, add_points=None, dtype=numpy.complex64):

    test_func = TestFunction(mshape, dtype, batch=batch, order=1)

    if add_points is None:
        add_points = [0] * len(mshape)
    xs = [get_spatial_grid(n, 1, add_points=ap) for n, ap in zip(mshape, add_points)]

    mdata_dev = thr.array((batch,) + mshape, dtype)
    axes = list(range(1, len(mshape)+1))

    dht_fw = DHT(mdata_dev, inverse=False, axes=axes, add_points=[0] + add_points)
    dht_inv = DHT(mdata_dev, inverse=True, axes=axes, add_points=[0] + add_points)
    dht_fw_c = dht_fw.compile(thr)
    dht_inv_c = dht_inv.compile(thr)

    xdata = test_func(*xs)
    xdata_dev = thr.to_device(xdata)

    # forward transform
    dht_fw_c(mdata_dev, xdata_dev)
    assert diff_is_negligible(mdata_dev.get(), test_func.mdata)

    # inverse transform
    dht_inv_c(xdata_dev, mdata_dev)
    assert diff_is_negligible(xdata_dev.get(), xdata)
Esempio n. 2
0
def test_high_order_forward(thr, ho_order, ho_shape):
    """
    Checks that if we change the mode space while keeping mode population the same,
    the result of forward transformation for orders higher than 1 do not change.
    """

    dtype = numpy.float32

    modes = TestFunction.generate_modes((ho_shape,), dtype)
    f1 = TestFunction((ho_shape,), dtype, order=ho_order, modes=modes)
    f2 = TestFunction((ho_shape + 1,), dtype, order=ho_order, modes=modes)

    xs1 = get_spatial_grid(ho_shape, ho_order)
    xs2 = get_spatial_grid(ho_shape + 1, ho_order)

    xdata1 = f1(xs1)
    xdata2 = f2(xs2)

    xdata1_dev = thr.to_device(xdata1)
    xdata2_dev = thr.to_device(xdata2)

    mdata1_dev = thr.array(ho_shape, dtype)
    mdata2_dev = thr.array(ho_shape + 1, dtype)

    dht_fw1 = DHT(mdata1_dev, inverse=False, order=ho_order)
    dht_fw2 = DHT(mdata2_dev, inverse=False, order=ho_order)
    dht_fw1_c = dht_fw1.compile(thr)
    dht_fw2_c = dht_fw2.compile(thr)

    dht_fw1_c(mdata1_dev, xdata1_dev)
    dht_fw2_c(mdata2_dev, xdata2_dev)

    mdata1 = mdata1_dev.get()
    mdata2 = mdata2_dev.get()

    assert diff_is_negligible(mdata1, mdata2[:-1])
Esempio n. 3
0
def check_errors_first_order(thr,
                             mshape,
                             batch,
                             add_points=None,
                             dtype=numpy.complex64):

    test_func = TestFunction(mshape, dtype, batch=batch, order=1)

    if add_points is None:
        add_points = [0] * len(mshape)
    xs = [
        get_spatial_grid(n, 1, add_points=ap)
        for n, ap in zip(mshape, add_points)
    ]

    mdata_dev = thr.array((batch, ) + mshape, dtype)
    axes = list(range(1, len(mshape) + 1))

    dht_fw = DHT(mdata_dev,
                 inverse=False,
                 axes=axes,
                 add_points=[0] + add_points)
    dht_inv = DHT(mdata_dev,
                  inverse=True,
                  axes=axes,
                  add_points=[0] + add_points)
    dht_fw_c = dht_fw.compile(thr)
    dht_inv_c = dht_inv.compile(thr)

    xdata = test_func(*xs)
    xdata_dev = thr.to_device(xdata)

    # forward transform
    dht_fw_c(mdata_dev, xdata_dev)
    assert diff_is_negligible(mdata_dev.get(), test_func.mdata)

    # inverse transform
    dht_inv_c(xdata_dev, mdata_dev)
    assert diff_is_negligible(xdata_dev.get(), xdata)
Esempio n. 4
0
def test_high_order_forward(thr, ho_order, ho_shape):
    """
    Checks that if we change the mode space while keeping mode population the same,
    the result of forward transformation for orders higher than 1 do not change.
    """

    dtype = numpy.float32

    modes = TestFunction.generate_modes((ho_shape, ), dtype)
    f1 = TestFunction((ho_shape, ), dtype, order=ho_order, modes=modes)
    f2 = TestFunction((ho_shape + 1, ), dtype, order=ho_order, modes=modes)

    xs1 = get_spatial_grid(ho_shape, ho_order)
    xs2 = get_spatial_grid(ho_shape + 1, ho_order)

    xdata1 = f1(xs1)
    xdata2 = f2(xs2)

    xdata1_dev = thr.to_device(xdata1)
    xdata2_dev = thr.to_device(xdata2)

    mdata1_dev = thr.array(ho_shape, dtype)
    mdata2_dev = thr.array(ho_shape + 1, dtype)

    dht_fw1 = DHT(mdata1_dev, inverse=False, order=ho_order)
    dht_fw2 = DHT(mdata2_dev, inverse=False, order=ho_order)
    dht_fw1_c = dht_fw1.compile(thr)
    dht_fw2_c = dht_fw2.compile(thr)

    dht_fw1_c(mdata1_dev, xdata1_dev)
    dht_fw2_c(mdata2_dev, xdata2_dev)

    mdata1 = mdata1_dev.get()
    mdata2 = mdata2_dev.get()

    assert diff_is_negligible(mdata1, mdata2[:-1])