def test_gradients(): ha = qshift('qshift_c')[0] hb = qshift('qshift_c')[1] im_t = torch.unsqueeze(torch.tensor(barbara, dtype=torch.float32, requires_grad=True), dim=0) y_t = coldfilt(im_t, prep_filt(ha, 1), prep_filt(hb, 1), np.sum(ha*hb) > 0) dy = np.random.randn(*tuple(y_t.shape)).astype('float32') torch.autograd.grad(y_t, im_t, grad_outputs=torch.tensor(dy))
def test_equal_numpy_qshift1(hp): if hp: ha = qshift('qshift_a')[4] hb = qshift('qshift_a')[5] else: ha = qshift('qshift_a')[0] hb = qshift('qshift_a')[1] ref = ref_coldfilt(barbara, ha, hb) y = coldfilt(barbara_t, prep_filt(ha, 1).to(dev), prep_filt(hb, 1).to(dev), highpass=hp) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)
def test_equal_small_in(hp): if hp: ha = qshift('qshift_a')[4] hb = qshift('qshift_a')[5] else: ha = qshift('qshift_a')[0] hb = qshift('qshift_a')[1] im = barbara[:,0:4,0:4] im_t = torch.unsqueeze(torch.tensor(im, dtype=torch.float32), dim=0).to(dev) ref = ref_coldfilt(im, ha, hb) y = coldfilt(im_t, prep_filt(ha, 1).to(dev), prep_filt(hb, 1).to(dev), highpass=hp) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)
def test_gradients(hp): if hp: ha = qshift('qshift_b')[4] hb = qshift('qshift_b')[5] else: ha = qshift('qshift_b')[0] hb = qshift('qshift_b')[1] im_t = torch.unsqueeze(torch.tensor(barbara, dtype=torch.float32, requires_grad=True), dim=0).to(dev) y_t = rowdfilt(im_t, prep_filt(ha, 1).to(dev), prep_filt(hb, 1).to(dev), highpass=hp) np.random.randn(*tuple(y_t.shape)).astype('float32')
def test_equal_small_in(): h = qshift('qshift_b')[0] im = barbara[:,0:4,0:4] im_t = torch.unsqueeze(torch.tensor(im, dtype=torch.float32), dim=0).to(dev) ref = ref_colfilter(im, h) y = colfilter(im_t, prep_filt(h, 1).to(dev)) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)
def test_qshift(): h = qshift('qshift_a')[0] y_op = colfilter(barbara_t, prep_filt(h, 1).to(dev)) assert list(y_op.shape)[1:] == bshape_extrarow
def test_equal_numpy_qshift1(): h = qshift('qshift_c')[0] ref = ref_colfilter(barbara, h) y = colfilter(barbara_t, prep_filt(h, 1).to(dev)) np.testing.assert_array_almost_equal(y[0].cpu(), ref, decimal=4)