| 150 | |
| 151 | template <typename Options> |
| 152 | static Graph* ParseExample(int batch_size, int num_keys, int feature_size) { |
| 153 | Graph* g = new Graph(OpRegistry::Global()); |
| 154 | Tensor& serialized = Options::Store::GetSerializedExample()[std::make_tuple( |
| 155 | batch_size, num_keys, feature_size)]; |
| 156 | Tensor names(DT_STRING, TensorShape({batch_size})); |
| 157 | |
| 158 | std::vector<NodeBuilder::NodeOut> sparse_keys; |
| 159 | std::vector<NodeBuilder::NodeOut> dense_keys; |
| 160 | std::vector<NodeBuilder::NodeOut> dense_defaults; |
| 161 | std::vector<DataType> sparse_types; |
| 162 | std::vector<PartialTensorShape> dense_shapes; |
| 163 | Options opt; |
| 164 | for (int i = 0; i < num_keys; ++i) { |
| 165 | Tensor key(DT_STRING, TensorShape()); |
| 166 | key.scalar<tstring>()() = strings::Printf("feature_%d", i); |
| 167 | switch (opt.benchmark_type) { |
| 168 | case kDense: |
| 169 | dense_keys.emplace_back(test::graph::Constant(g, key)); |
| 170 | dense_defaults.emplace_back(test::graph::Constant( |
| 171 | g, opt.filler.make_dense_default(feature_size))); |
| 172 | dense_shapes.push_back(PartialTensorShape({feature_size})); |
| 173 | break; |
| 174 | case kVarLenDense: |
| 175 | dense_keys.emplace_back(test::graph::Constant(g, key)); |
| 176 | dense_defaults.emplace_back( |
| 177 | test::graph::Constant(g, opt.filler.make_dense_default(1))); |
| 178 | dense_shapes.push_back(PartialTensorShape({-1})); |
| 179 | break; |
| 180 | case kSparse: |
| 181 | sparse_keys.emplace_back(test::graph::Constant(g, key)); |
| 182 | sparse_types.push_back(opt.filler.dtype); |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | Node* ret; |
| 188 | TF_EXPECT_OK(NodeBuilder(g->NewName("n"), "ParseExample") |
| 189 | .Input(test::graph::Constant(g, serialized)) |
| 190 | .Input(test::graph::Constant(g, names)) |
| 191 | .Input(sparse_keys) |
| 192 | .Input(dense_keys) |
| 193 | .Input(dense_defaults) |
| 194 | .Attr("sparse_types", sparse_types) |
| 195 | .Attr("dense_shapes", dense_shapes) |
| 196 | .Finalize(g, &ret)); |
| 197 | |
| 198 | return g; |
| 199 | } |
| 200 | |
| 201 | template <typename Options> |
| 202 | static Graph* ParseSingleExample(int num_keys, int feature_size) { |
no test coverage detected