def test_cpu_kernel():
     shape = (2, 128, 10)
     k = 2
     paddle.set_device('cpu')
     inputs = np.random.random(shape)
     tensor = paddle.to_tensor(inputs)
     for axis in self.axises:
         value_expect, indice_expect = cal_kthvalue(inputs, k, axis)
         v, inds = paddle.kthvalue(tensor, k, axis)
         self.assertTrue(np.allclose(v.numpy(), value_expect))
         self.assertTrue(np.allclose(inds.numpy(), indice_expect))
 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, 20, 1, 2, 80],
                                           dtype="float64")
         result = paddle.kthvalue(input_tensor, self.k, axis=1)
         expect_value = cal_kthvalue(self.input_data, self.k, 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))