| 120 | public ::testing::WithParamInterface<TestCase> {}; |
| 121 | |
| 122 | TEST_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 | |
| 172 | TEST_F(TensorDatasetOpTest, DatasetTypeString) { |
| 173 | int thread_num = 2, cpu_num = 2; |
nothing calls this directly
no test coverage detected