From e7fa61e2820b8d2eadbd1f48d2de9236c82aebbf Mon Sep 17 00:00:00 2001 From: peizhilin Date: Tue, 15 Jan 2019 21:24:07 +0800 Subject: [PATCH] fix unit test cases test=develop --- .../test_recommender_system_newapi.py | 19 ++++++++++-------- .../tests/book/test_recommender_system.py | 20 +++++++++++-------- .../fluid/tests/unittests/test_auc_op.py | 2 +- .../paddle/fluid/tests/unittests/test_nce.py | 3 ++- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py b/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py index 8219373796..07afa742c6 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py +++ b/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py @@ -231,14 +231,17 @@ def infer(use_cuda, inference_program, params_dirname): # Correspondingly, recursive_sequence_lengths = [[3, 2]] contains one # level of detail info, indicating that `data` consists of two sequences # of length 3 and 2, respectively. - user_id = fluid.create_lod_tensor([[1]], [[1]], place) - gender_id = fluid.create_lod_tensor([[1]], [[1]], place) - age_id = fluid.create_lod_tensor([[0]], [[1]], place) - job_id = fluid.create_lod_tensor([[10]], [[1]], place) - movie_id = fluid.create_lod_tensor([[783]], [[1]], place) - category_id = fluid.create_lod_tensor([[10, 8, 9]], [[3]], place) - movie_title = fluid.create_lod_tensor([[1069, 4140, 2923, 710, 988]], [[5]], - place) + user_id = fluid.create_lod_tensor([[np.int64(1)]], [[1]], place) + gender_id = fluid.create_lod_tensor([[np.int64(1)]], [[1]], place) + age_id = fluid.create_lod_tensor([[np.int64(0)]], [[1]], place) + job_id = fluid.create_lod_tensor([[np.int64(10)]], [[1]], place) + movie_id = fluid.create_lod_tensor([[np.int64(783)]], [[1]], place) + category_id = fluid.create_lod_tensor( + [np.array( + [10, 8, 9], dtype='int64')], [[3]], place) + movie_title = fluid.create_lod_tensor( + [np.array( + [1069, 4140, 2923, 710, 988], dtype='int64')], [[5]], place) results = inferencer.infer( { diff --git a/python/paddle/fluid/tests/book/test_recommender_system.py b/python/paddle/fluid/tests/book/test_recommender_system.py index cf8c48f346..0e1efc8212 100644 --- a/python/paddle/fluid/tests/book/test_recommender_system.py +++ b/python/paddle/fluid/tests/book/test_recommender_system.py @@ -271,26 +271,30 @@ def infer(use_cuda, save_dirname=None): # Correspondingly, recursive_sequence_lengths = [[3, 2]] contains one # level of detail info, indicating that `data` consists of two sequences # of length 3 and 2, respectively. - user_id = fluid.create_lod_tensor([[1]], [[1]], place) + user_id = fluid.create_lod_tensor([[np.int64(1)]], [[1]], place) assert feed_target_names[1] == "gender_id" - gender_id = fluid.create_lod_tensor([[1]], [[1]], place) + gender_id = fluid.create_lod_tensor([[np.int64(1)]], [[1]], place) assert feed_target_names[2] == "age_id" - age_id = fluid.create_lod_tensor([[0]], [[1]], place) + age_id = fluid.create_lod_tensor([[np.int64(0)]], [[1]], place) assert feed_target_names[3] == "job_id" - job_id = fluid.create_lod_tensor([[10]], [[1]], place) + job_id = fluid.create_lod_tensor([[np.int64(10)]], [[1]], place) assert feed_target_names[4] == "movie_id" - movie_id = fluid.create_lod_tensor([[783]], [[1]], place) + movie_id = fluid.create_lod_tensor([[np.int64(783)]], [[1]], place) assert feed_target_names[5] == "category_id" - category_id = fluid.create_lod_tensor([[10, 8, 9]], [[3]], place) + category_id = fluid.create_lod_tensor( + [np.array( + [10, 8, 9], dtype='int64')], [[3]], place) assert feed_target_names[6] == "movie_title" - movie_title = fluid.create_lod_tensor([[1069, 4140, 2923, 710, 988]], - [[5]], place) + movie_title = fluid.create_lod_tensor( + [np.array( + [1069, 4140, 2923, 710, 988], dtype='int64')], [[5]], + place) # Construct feed as a dictionary of {feed_target_name: feed_target_data} # and results will contain a list of data corresponding to fetch_targets. diff --git a/python/paddle/fluid/tests/unittests/test_auc_op.py b/python/paddle/fluid/tests/unittests/test_auc_op.py index 810e8a1a85..b75abd424a 100644 --- a/python/paddle/fluid/tests/unittests/test_auc_op.py +++ b/python/paddle/fluid/tests/unittests/test_auc_op.py @@ -24,7 +24,7 @@ class TestAucOp(OpTest): def setUp(self): self.op_type = "auc" pred = np.random.random((128, 2)).astype("float32") - labels = np.random.randint(0, 2, (128, 1)) + labels = np.random.randint(0, 2, (128, 1)).astype("int64") num_thresholds = 200 stat_pos = np.zeros((num_thresholds + 1, )).astype("int64") diff --git a/python/paddle/fluid/tests/unittests/test_nce.py b/python/paddle/fluid/tests/unittests/test_nce.py index f4f9744674..1e462d13d0 100644 --- a/python/paddle/fluid/tests/unittests/test_nce.py +++ b/python/paddle/fluid/tests/unittests/test_nce.py @@ -68,7 +68,8 @@ class TestNCE(OpTest): weight = np.random.randn(num_classes, dim).astype(np.float32) bias = np.random.randn(num_classes).astype(np.float32) sample_weight = np.random.randn(batch_size).astype(np.float32) - labels = np.random.randint(0, num_classes, (batch_size, num_true_class)) + labels = np.random.randint(0, num_classes, + (batch_size, num_true_class)).astype("int64") self.attrs = { 'num_total_classes': num_classes, 'num_neg_samples': num_neg_samples, -- GitLab