示例#1
0
def test_lfilter_2():
    b = (0.96907117, -2.90721352, 2.90721352, -0.96907117)
    a = (1., -2.93717073, 2.87629972, -0.93909894)
    arr = np.random.rand(1000, 100).astype(np.float32)

    fil_gpu = cp.asnumpy(lfilter(b, a, cp.asarray(arr), axis=0))
    fil_cpu = lfilter_cpu(b, a, arr, axis=0)

    assert np.allclose(fil_cpu, fil_gpu, atol=.2)
示例#2
0
def create_test_dataset():
    cp = np  # cpu mode only here
    s1 = np.load(test_path.joinpath('my_conv2_input.npy'))
    s0 = np.copy(s1)
    tmax = np.ceil(4 * sig)
    dt = cp.arange(-tmax, tmax + 1)
    gauss = cp.exp(-dt**2 / (2 * sig**2))
    gauss = (gauss / cp.sum(gauss)).astype(np.float32)

    cNorm = lfilter_cpu(gauss, 1., np.r_[np.ones(s1.shape[0]),
                                         np.zeros(int(tmax))])
    cNorm = cNorm[int(tmax):]

    s1 = lfilter_cpu(gauss,
                     1,
                     np.r_[s1, np.zeros((int(tmax), s1.shape[1]))],
                     axis=0)
    s1 = s1[int(tmax):] / cNorm[:, np.newaxis]

    np.save(test_path.joinpath('my_conv2_output.npy'), s1)
示例#3
0
def test_lfilter_1():
    tmax = 1000
    dt = np.arange(-tmax, tmax + 1)
    gaus = np.exp(-dt ** 2 / (2 * 250 ** 2))
    b = gaus / np.sum(gaus)

    a = 1.

    n = 2000
    arr = np.r_[np.ones(n), np.zeros(n)]

    fil_gpu = cp.asnumpy(lfilter(b, a, cp.asarray(arr), axis=0)).ravel()
    fil_cpu = lfilter_cpu(b, a, arr, axis=0)

    assert np.allclose(fil_cpu, fil_gpu, atol=1e-6)