| 148 | public ::testing::WithParamInterface<TestCase> {}; |
| 149 | |
| 150 | TEST_P(ParameterizedTakeDatasetOpTest, GetNext) { |
| 151 | int thread_num = 2, cpu_num = 2; |
| 152 | TF_ASSERT_OK(InitThreadPool(thread_num)); |
| 153 | TF_ASSERT_OK(InitFunctionLibraryRuntime({}, cpu_num)); |
| 154 | const TestCase &test_case = GetParam(); |
| 155 | Tensor tensor_slice_dataset_tensor(DT_VARIANT, TensorShape({})); |
| 156 | std::vector<Tensor> inputs_for_tensor_slice_dataset = test_case.input_tensors; |
| 157 | TF_ASSERT_OK(CreateTensorSliceDatasetTensor(&inputs_for_tensor_slice_dataset, |
| 158 | &tensor_slice_dataset_tensor)); |
| 159 | Tensor count = CreateTensor<int64>(TensorShape{}, {test_case.count}); |
| 160 | gtl::InlinedVector<TensorValue, 4> inputs_for_take_dataset; |
| 161 | inputs_for_take_dataset.emplace_back(&tensor_slice_dataset_tensor); |
| 162 | inputs_for_take_dataset.emplace_back(&count); |
| 163 | |
| 164 | std::unique_ptr<OpKernel> take_dataset_kernel; |
| 165 | TF_ASSERT_OK(CreateTakeDatasetKernel(test_case.expected_output_dtypes, |
| 166 | test_case.expected_output_shapes, |
| 167 | &take_dataset_kernel)); |
| 168 | std::unique_ptr<OpKernelContext> take_dataset_context; |
| 169 | TF_ASSERT_OK(CreateTakeDatasetContext(take_dataset_kernel.get(), |
| 170 | &inputs_for_take_dataset, |
| 171 | &take_dataset_context)); |
| 172 | DatasetBase *take_dataset; |
| 173 | TF_ASSERT_OK(CreateDataset(take_dataset_kernel.get(), |
| 174 | take_dataset_context.get(), &take_dataset)); |
| 175 | core::ScopedUnref scoped_unref(take_dataset); |
| 176 | |
| 177 | std::unique_ptr<IteratorContext> iterator_ctx; |
| 178 | TF_ASSERT_OK( |
| 179 | CreateIteratorContext(take_dataset_context.get(), &iterator_ctx)); |
| 180 | std::unique_ptr<IteratorBase> iterator; |
| 181 | TF_ASSERT_OK( |
| 182 | take_dataset->MakeIterator(iterator_ctx.get(), "Iterator", &iterator)); |
| 183 | |
| 184 | auto expected_outputs_it = test_case.expected_outputs.begin(); |
| 185 | bool end_of_sequence = false; |
| 186 | std::vector<Tensor> out_tensors; |
| 187 | while (!end_of_sequence) { |
| 188 | TF_EXPECT_OK( |
| 189 | iterator->GetNext(iterator_ctx.get(), &out_tensors, &end_of_sequence)); |
| 190 | if (!end_of_sequence) { |
| 191 | for (const auto &tensor : out_tensors) { |
| 192 | EXPECT_NE(expected_outputs_it, test_case.expected_outputs.end()); |
| 193 | TF_EXPECT_OK(ExpectEqual(tensor, *expected_outputs_it)); |
| 194 | expected_outputs_it++; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | EXPECT_EQ(expected_outputs_it, test_case.expected_outputs.end()); |
| 199 | } |
| 200 | |
| 201 | TEST_F(TakeDatasetOpTest, DatasetNodeName) { |
| 202 | int thread_num = 2, cpu_num = 2; |
nothing calls this directly
no test coverage detected