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

Function TEST

tensorflow/core/framework/hash_table/tensible_variable_test.cc:34–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32};
33
34TEST(TensibleVariable, Simple) {
35 Status ok;
36 Tensor a(DT_INT64, TensorShape({10})), b(DT_INT64, TensorShape({10}));
37 std::vector<Tensor> tensors;
38 for (int i = 0; i < 10; i++) {
39 tensors.emplace_back(DT_INT64, TensorShape({5, 2}));
40 auto f = tensors[i].flat<int64>();
41 for (int j = 0; j < 10; j++) {
42 f(j) = i * 10 + j;
43 }
44 }
45 MockProducer producer;
46 EXPECT_CALL(producer, Produce())
47 .WillOnce(::testing::Return(std::make_pair(ok, tensors[0])))
48 .WillOnce(::testing::Return(std::make_pair(ok, tensors[1])))
49 .WillOnce(::testing::Return(std::make_pair(ok, tensors[2])))
50 .WillOnce(::testing::Return(std::make_pair(ok, tensors[3])))
51 .WillOnce(::testing::Return(std::make_pair(ok, tensors[4])))
52 .WillOnce(::testing::Return(std::make_pair(ok, tensors[5])))
53 .WillOnce(::testing::Return(std::make_pair(ok, tensors[6])))
54 .WillOnce(::testing::Return(std::make_pair(ok, tensors[7])))
55 .WillOnce(::testing::Return(std::make_pair(ok, tensors[8])))
56 .WillOnce(::testing::Return(std::make_pair(ok, tensors[9])));
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
70 tv->Resize(4, consumer);
71 TF_EXPECT_OK(rst_status);
72 EXPECT_EQ(5, tv->Size());
73
74 for (int i = 0; i < 4; i++) {
75 EXPECT_EQ(i * 2 + 0, tv->GetSlice<int64>(i)[0]);
76 EXPECT_EQ(i * 2 + 1, tv->GetSlice<int64>(i)[1]);
77 }
78
79 tv->Resize(23, consumer);
80 TF_EXPECT_OK(rst_status);
81 EXPECT_EQ(25, tv->Size());
82
83 for (int i = 0; i < 23; i++) {
84 EXPECT_EQ(i * 2 + 0, tv->GetSlice<int64>(i)[0]);
85 EXPECT_EQ(i * 2 + 1, tv->GetSlice<int64>(i)[1]);
86 }
87
88 EXPECT_EQ(5, tv->SegmentSize());
89 EXPECT_EQ(TensorShape({5, 2}), tv->shape());
90 EXPECT_EQ(DT_INT64, tv->dtype());
91 EXPECT_EQ(2 * sizeof(int64), tv->SliceSize());

Callers

nothing calls this directly

Calls 11

SegmentSizeMethod · 0.80
SliceSizeMethod · 0.80
TensorShapeClass · 0.50
fFunction · 0.50
emplace_backMethod · 0.45
ProduceMethod · 0.45
UnrefMethod · 0.45
ResizeMethod · 0.45
SizeMethod · 0.45
shapeMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected