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

Function TEST_P

tensorflow/core/kernels/data/tensor_dataset_op_test.cc:122–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 public ::testing::WithParamInterface<TestCase> {};
121
122TEST_P(ParametrizedTensorDatasetOpTest, GetNext) {
123 int thread_num = 2, cpu_num = 2;
124 TF_ASSERT_OK(InitThreadPool(thread_num));
125 TF_ASSERT_OK(InitFunctionLibraryRuntime({}, cpu_num));
126
127 const TestCase &test_case = GetParam();
128 std::vector<Tensor> components = test_case.components;
129 gtl::InlinedVector<TensorValue, 4> inputs;
130 for (auto &component : components) {
131 inputs.push_back(TensorValue(&component));
132 }
133 std::unique_ptr<OpKernel> tensor_dataset_kernel;
134 TF_ASSERT_OK(CreateTensorDatasetKernel(test_case.expected_output_dtypes,
135 test_case.expected_output_shapes,
136 &tensor_dataset_kernel));
137 std::unique_ptr<OpKernelContext> tensor_dataset_context;
138 TF_ASSERT_OK(CreateTensorDatasetContext(tensor_dataset_kernel.get(), &inputs,
139 &tensor_dataset_context));
140 DatasetBase *tensor_dataset;
141 TF_ASSERT_OK(CreateDataset(tensor_dataset_kernel.get(),
142 tensor_dataset_context.get(), &tensor_dataset));
143 core::ScopedUnref scoped_unref(tensor_dataset);
144
145 std::unique_ptr<IteratorContext> iterator_context;
146 TF_ASSERT_OK(
147 CreateIteratorContext(tensor_dataset_context.get(), &iterator_context));
148 std::unique_ptr<IteratorBase> iterator;
149 TF_ASSERT_OK(tensor_dataset->MakeIterator(iterator_context.get(), "Iterator",
150 &iterator));
151 bool end_of_sequence = false;
152 std::vector<Tensor> out_tensors;
153 while (!end_of_sequence) {
154 TF_EXPECT_OK(iterator->GetNext(iterator_context.get(), &out_tensors,
155 &end_of_sequence));
156 }
157 EXPECT_EQ(out_tensors.size(), test_case.expected_outputs.size());
158 for (int i = 0; i < out_tensors.size(); ++i) {
159 if (out_tensors[i].dtype() == DT_VARIANT) {
160 // Currently `ExpectEqual()` does not support the variant tensor
161 // yet, so we manually cast the variant to numeric/string tensor.
162 const Tensor *output = out_tensors[i].scalar<Variant>()().get<Tensor>();
163 const Tensor *expected_output =
164 test_case.expected_outputs[i].scalar<Variant>()().get<Tensor>();
165 TF_EXPECT_OK(ExpectEqual(*output, *expected_output));
166 } else {
167 TF_EXPECT_OK(ExpectEqual(out_tensors[i], test_case.expected_outputs[i]));
168 }
169 }
170}
171
172TEST_F(TensorDatasetOpTest, DatasetTypeString) {
173 int thread_num = 2, cpu_num = 2;

Callers

nothing calls this directly

Calls 14

GetParamFunction · 0.85
TensorValueClass · 0.85
ExpectEqualFunction · 0.50
push_backMethod · 0.45
getMethod · 0.45
MakeIteratorMethod · 0.45
GetNextMethod · 0.45
sizeMethod · 0.45
dtypeMethod · 0.45
output_dtypesMethod · 0.45
output_shapesMethod · 0.45
IsIdenticalToMethod · 0.45

Tested by

no test coverage detected