def test_Restriction_2dsignal(par): """Dot-test, forward and adjoint for Restriction operator for 2d signal """ np.random.seed(10) x = np.ones((par['nx'], par['nt'])) + \ par['imag'] * np.ones((par['nx'], par['nt'])) # 1st direction Nsub = int(np.round(par['nx'] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par['nx']))[:Nsub]) Rop = Restriction(par['nx'] * par['nt'], iava, dims=(par['nx'], par['nt']), dir=0, inplace=par['dtype'], dtype=par['dtype']) assert dottest(Rop, Nsub * par['nt'], par['nx'] * par['nt'], complexflag=0 if par['imag'] == 0 else 3) y = (Rop * x.ravel()).reshape(Nsub, par['nt']) x1 = (Rop.H * y.ravel()).reshape(par['nx'], par['nt']) y1_fromflat = Rop.mask(x.ravel()) y1 = Rop.mask(x) assert_array_almost_equal(y, y1_fromflat.reshape(par['nx'], par['nt'])[iava]) assert_array_almost_equal(y, y1[iava]) assert_array_almost_equal(x[iava], x1[iava]) # 2nd direction Nsub = int(np.round(par['nt'] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par['nt']))[:Nsub]) Rop = Restriction(par['nx'] * par['nt'], iava, dims=(par['nx'], par['nt']), dir=1, inplace=par['dtype'], dtype=par['dtype']) assert dottest(Rop, par['nx'] * Nsub, par['nx'] * par['nt'], complexflag=0 if par['imag'] == 0 else 3) y = (Rop * x.ravel()).reshape(par['nx'], Nsub) x1 = (Rop.H * y.ravel()).reshape(par['nx'], par['nt']) y1_fromflat = Rop.mask(x.ravel()) y1 = Rop.mask(x) assert_array_almost_equal(y, y1_fromflat[:, iava]) assert_array_almost_equal(y, y1[:, iava]) assert_array_almost_equal(x[:, iava], x1[:, iava])
def test_Restriction_1dsignal(par): """Dot-test, forward and adjoint for Restriction operator for 1d signal""" np.random.seed(10) Nsub = int(np.round(par["nx"] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par["nx"]))[:Nsub]) Rop = Restriction(par["nx"], iava, inplace=par["dtype"], dtype=par["dtype"]) assert dottest(Rop, Nsub, par["nx"], complexflag=0 if par["imag"] == 0 else 3) x = np.ones(par["nx"]) + par["imag"] * np.ones(par["nx"]) y = Rop * x x1 = Rop.H * y y1 = Rop.mask(x) assert_array_almost_equal(y, y1[iava]) assert_array_almost_equal(x[iava], x1[iava])
def test_Restriction(par): """Dot-test, forward and adjoint for Restriction operator """ # subsampling locations np.random.seed(10) perc_subsampling = 0.4 Nsub = int(np.round(par['nx'] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par['nx']))[:Nsub]) Rop = Restriction(par['nx'], iava, dtype=par['dtype']) assert dottest(Rop, Nsub, par['nx'], complexflag=0 if par['imag'] == 0 else 3) x = np.ones(par['nx']) + par['imag'] * np.ones(par['nx']) y = Rop * x x1 = Rop.H * y y1 = Rop.mask(x) assert_array_almost_equal(y, y1[iava]) assert_array_almost_equal(x[iava], x1[iava])