def test_roll_op_api(self):
    self.input_data()
    with program_guard(Program(), Program()):
        x = fluid.layers.data(name='x', shape=[(- 1), 3])
        z = paddle.roll(x, shifts=1)
        exe = fluid.Executor(fluid.CPUPlace())
        (res,) = exe.run(feed={'x': self.data_x}, fetch_list=[z.name], return_numpy=False)
        expect_out = np.array([[9.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])
        self.assertTrue(np.allclose(expect_out, np.array(res)))
    with program_guard(Program(), Program()):
        x = fluid.layers.data(name='x', shape=[(- 1), 3])
        z = paddle.roll(x, shifts=1, dims=0)
        exe = fluid.Executor(fluid.CPUPlace())
        (res,) = exe.run(feed={'x': self.data_x}, fetch_list=[z.name], return_numpy=False)
    expect_out = np.array([[7.0, 8.0, 9.0], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
    self.assertTrue(np.allclose(expect_out, np.array(res)))
def test_roll_op_api(self):
    self.input_data()
    with program_guard(Program(), Program()):
        x = fluid.layers.data(name='x', shape=[(- 1), 3])
        z = paddle.roll(x, shifts=1)
        exe = fluid.Executor(fluid.CPUPlace())
        (res,) = exe.run(feed={'x': self.data_x}, fetch_list=[z.name], return_numpy=False)
        expect_out = np.array([[9.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])
        self.assertTrue(np.allclose(expect_out, np.array(res)))
    with program_guard(Program(), Program()):
        x = fluid.layers.data(name='x', shape=[(- 1), 3])
        z = paddle.roll(x, shifts=1, dims=0)
        exe = fluid.Executor(fluid.CPUPlace())
        (res,) = exe.run(feed={'x': self.data_x}, fetch_list=[z.name], return_numpy=False)
    expect_out = np.array([[7.0, 8.0, 9.0], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
    self.assertTrue(np.allclose(expect_out, np.array(res)))