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

Function TestFastParse

tensorflow/core/util/example_proto_fast_parsing.cc:382–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380} // namespace
381
382bool TestFastParse(const string& serialized, Example* example) {
383 DCHECK(example != nullptr);
384 parsed::Example parsed_example;
385 if (!ParseExample(serialized, &parsed_example)) return false;
386 auto& features = *example->mutable_features();
387 size_t parsed_example_size = parsed_example.size();
388 for (size_t i = 0; i < parsed_example_size; ++i) {
389 // This is a logic that standard protobuf parsing is implementing.
390 // I.e. last entry in the map overwrites all the previous ones.
391 parsed::FeatureMapEntry& name_and_feature =
392 parsed_example[parsed_example_size - i - 1];
393 string name(name_and_feature.first);
394 if ((*features.mutable_feature()).count(name) > 0) continue;
395
396 auto& value = (*features.mutable_feature())[name];
397 DataType dtype;
398 if (!name_and_feature.second.ParseDataType(&dtype).ok()) return false;
399 switch (dtype) {
400 case DT_INVALID:
401 break;
402 case DT_STRING: {
403 SmallVector<string> list;
404 if (!name_and_feature.second.ParseBytesList(&list)) return false;
405 auto* result_list = value.mutable_bytes_list();
406 for (auto& bytes : list) {
407 auto* new_value = result_list->add_value();
408 new_value->swap(bytes);
409 }
410 break;
411 }
412 case DT_FLOAT: {
413 SmallVector<float> list;
414 if (!name_and_feature.second.ParseFloatList(&list)) return false;
415 auto* result_list = value.mutable_float_list();
416 for (float f : list) {
417 result_list->add_value(f);
418 }
419 break;
420 }
421 case DT_INT64: {
422 SmallVector<int64> list;
423 if (!name_and_feature.second.ParseInt64List(&list)) return false;
424 auto* result_list = value.mutable_int64_list();
425 for (int64 i : list) {
426 result_list->add_value(i);
427 }
428 break;
429 }
430 default:
431 LOG(FATAL) << "Should not happen.";
432 }
433 }
434 return true;
435}
436
437// -----------------------------------------------------------------------------
438

Callers 1

TestCorrectnessFunction · 0.85

Calls 9

ParseDataTypeMethod · 0.80
ParseBytesListMethod · 0.80
ParseFloatListMethod · 0.80
ParseExampleFunction · 0.70
sizeMethod · 0.45
countMethod · 0.45
okMethod · 0.45
swapMethod · 0.45
ParseInt64ListMethod · 0.45

Tested by

no test coverage detected