MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/framework/hash_table/hash_table_test.cc:36–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36TEST(HashTable, Simple) {
37 Status ok;
38 Tensor a(DT_INT64, TensorShape({10})), b(DT_INT64, TensorShape({10}));
39 std::vector<Tensor> tensors;
40 for (int i = 0; i < 10; i++) {
41 tensors.emplace_back(DT_INT64, TensorShape({5, 2}));
42 auto f = tensors[i].flat<int64>();
43 for (int j = 0; j < 10; j++) {
44 f(j) = i * 10 + j;
45 }
46 }
47 MockProducer producer;
48 EXPECT_CALL(producer, Produce())
49 .WillOnce(::testing::Return(std::make_pair(ok, tensors[0])))
50 .WillOnce(::testing::Return(std::make_pair(ok, tensors[1])))
51 .WillOnce(::testing::Return(std::make_pair(ok, tensors[2])))
52 .WillOnce(::testing::Return(std::make_pair(ok, tensors[3])))
53 .WillOnce(::testing::Return(std::make_pair(ok, tensors[4])))
54 .WillOnce(::testing::Return(std::make_pair(ok, tensors[5])))
55 .WillOnce(::testing::Return(std::make_pair(ok, tensors[6])))
56 .WillOnce(::testing::Return(std::make_pair(ok, tensors[7])));
57 Status rst_status;
58 TensorGenerator* generator = new TensorGenerator(
59 [&](TensorGenerator::Consumer consumer) {
60 auto rst = producer.Produce();
61 consumer(rst.first, rst.second);
62 });
63 auto consumer = [&](Status st) {
64 rst_status = st;
65 };
66 TensibleVariable* tv = new TensibleVariable(
67 generator, TensorShape({5, 2}), DT_INT64);
68 generator->Unref();
69 HashTable ht(2, true, 7, 3);
70 ht.AddTensible(tv, consumer);
71 TF_ASSERT_OK(rst_status);
72 tv->Unref();
73
74 {
75 int64 keys[8] = {105, 100, 101, 102, 103, 100, 101, 104};
76 int64 ids[8];
77 int64 result[8] = {0, 1, 5, 2, 3, 1, 5, 6};
78 ht.GetIds(keys, nullptr, ids, 8, nullptr, nullptr, consumer, false);
79
80 for (int i = 0; i < 8; i++) {
81 EXPECT_EQ(result[i], ids[i]);
82 }
83 EXPECT_EQ(10, tv->Size());
84 }
85
86 {
87 int64 keys[9] = {105 + 64, 100 + 64, 101 + 64, 102 + 64, 103 + 64, 100 + 64, 101 + 64, 104 + 64, 106 + 64};
88 int64 ids[9];
89 int64 result[9] = {4, 8, 7, 9, 10, 8, 7, 13, 11};
90 ht.GetIds(keys, nullptr, ids, 9, nullptr, nullptr, consumer, false);
91
92 for (int i = 0; i < 9; i++) {
93 EXPECT_EQ(result[i], ids[i]);

Callers

nothing calls this directly

Calls 8

AddTensibleMethod · 0.80
GetIdsMethod · 0.80
TensorShapeClass · 0.50
fFunction · 0.50
emplace_backMethod · 0.45
ProduceMethod · 0.45
UnrefMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected