Exemple #1
0
        def test_gpu_kernel():
            paddle.set_device('gpu')
            tensor = paddle.to_tensor(self.inputs)
            for axis in self.axises:
                value_expect, indice_expect = cal_mode(self.inputs, axis)
                v, inds = paddle.mode(tensor, axis)
                self.assertTrue(np.allclose(v.numpy(), value_expect))

                value_expect, indice_expect = cal_mode(
                    self.inputs, axis, keepdim=True)
                v, inds = paddle.mode(tensor, axis, keepdim=True)
                self.assertTrue(np.allclose(v.numpy(), value_expect))
Exemple #2
0
    def test_run_static(self):
        paddle.enable_static()
        with paddle.static.program_guard(paddle.static.Program(),
                                         paddle.static.Program()):
            input_tensor = paddle.static.data(
                name="x", shape=[2, 10, 10], dtype="float64")

            result = paddle.mode(input_tensor, axis=1)
            expect_value = cal_mode(self.input_data, axis=1)[0]
            exe = paddle.static.Executor(paddle.CPUPlace())
            paddle_result = exe.run(feed={"x": self.input_data},
                                    fetch_list=[result])[0]
            self.assertTrue(np.allclose(paddle_result, expect_value))