def testPadWithOneReflectionIsCorrect(self): """Tests that pad_reflecting(p) matches np.pad(p) when p is small.""" for _ in range(4): n = int(np.ceil(np.random.uniform() * 8)) + 1 x = np.random.uniform(size=(n, n, n)) padding_below = int(np.round(np.random.uniform() * (n - 1))) padding_above = int(np.round(np.random.uniform() * (n - 1))) axis = int(np.floor(np.random.uniform() * 3.)) if axis == 0: reference = np.pad( x, [[padding_below, padding_above], [0, 0], [0, 0]], 'reflect') elif axis == 1: reference = np.pad( x, [[0, 0], [padding_below, padding_above], [0, 0]], 'reflect') elif axis == 2: reference = np.pad( x, [[0, 0], [0, 0], [padding_below, padding_above]], 'reflect') result = wavelet.pad_reflecting(x, padding_below, padding_above, axis) np.testing.assert_equal(result.shape, reference.shape) np.testing.assert_equal(result, reference)
def testPadWithManyReflectionsIsCorrect(self): """Tests that pad_reflecting(k * p) matches np.pad(p) applied k times.""" for _ in range(4): n = int(np.random.uniform() * 8.) + 1 p = n - 1 x = np.random.uniform(size=(n)) reference1 = np.pad(x, [[p, p]], 'reflect') reference2 = np.pad(reference1, [[p, p]], 'reflect') reference3 = np.pad(reference2, [[p, p]], 'reflect') result1 = wavelet.pad_reflecting(x, p, p, 0) result2 = wavelet.pad_reflecting(x, 2 * p, 2 * p, 0) result3 = wavelet.pad_reflecting(x, 3 * p, 3 * p, 0) np.testing.assert_equal(result1.shape, reference1.shape) np.testing.assert_equal(result1, reference1) np.testing.assert_equal(result2.shape, reference2.shape) np.testing.assert_equal(result2, reference2) np.testing.assert_equal(result3.shape, reference3.shape) np.testing.assert_equal(result3, reference3)
def testPadWithManyReflectionsGolden2IsCorrect(self): """Tests pad_reflecting() against a golden example.""" n = 11 p0 = 15 p1 = 7 x = np.arange(n) reference = np.concatenate((np.arange(5, n), np.arange(n - 2, 0, -1), np.arange(n), np.arange(n - 2, 2, -1))) result = wavelet.pad_reflecting(x, p0, p1, 0) np.testing.assert_equal(result.shape, reference.shape) np.testing.assert_equal(result, reference)