def test_roll_2d_a(self) -> None: a1 = np.arange(12).reshape((3,4)) for i in range(a1.shape[0] + 1): post = roll_2d(a1, i, axis=0) self.assertEqual(post.tolist(), np.roll(a1, i, axis=0).tolist()) post = roll_2d(a1, -i, axis=0) self.assertEqual(post.tolist(), np.roll(a1, -i, axis=0).tolist()) for i in range(a1.shape[1] + 1): post = roll_2d(a1, i, axis=1) self.assertEqual(post.tolist(), np.roll(a1, i, axis=1).tolist()) post = roll_2d(a1, -i, axis=1) self.assertEqual(post.tolist(), np.roll(a1, -i, axis=1).tolist())
def test_roll_2d(self, array: np.ndarray, shift: int) -> None: for axis in (0, 1): post = util.roll_2d(array, shift=shift, axis=axis) self.assertEqual(post.shape, array.shape) start = -(shift % array.shape[axis]) if axis == 0: a = array[start] b = post[0] else: a = array[:, start] b = post[:, 0] self.assertAlmostEqualValues(a, b)
def test_roll_2d_b(self) -> None: post = roll_2d(np.array([[]]), -4, axis=1) self.assertEqual(post.shape, (1, 0))