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

Function GetTensorIndices

tensorflow/compiler/mlir/lite/flatbuffer_import.cc:635–657  ·  view source on GitHub ↗

Returns indices of the given tensors in the subgraph. Returns error if a tensor name cannot be found in the subgraph.

Source from the content-addressed store, hash-verified

633// Returns indices of the given tensors in the subgraph. Returns error if a
634// tensor name cannot be found in the subgraph.
635StatusOr<std::vector<int>> GetTensorIndices(
636 const tflite::SubGraphT& subgraph,
637 const std::vector<std::string>& tensor_names) {
638 absl::flat_hash_map<std::string, int> name_to_index;
639 for (auto index_and_tensor : llvm::enumerate(subgraph.tensors)) {
640 name_to_index[index_and_tensor.value()->name] = index_and_tensor.index();
641 }
642
643 std::vector<int> indices;
644 indices.reserve(tensor_names.size());
645
646 for (const auto& name : tensor_names) {
647 auto found = name_to_index.find(name);
648 if (found != name_to_index.end()) {
649 indices.push_back(found->second);
650 } else {
651 return errors::InvalidArgument("could not find tensor in subgraph: ",
652 name);
653 }
654 }
655
656 return indices;
657}
658
659// Given a list of tensor indices, returns a string of concatenated tensor names
660// wrapped in a NamedAttribute.

Callers 1

ConvertSubgraphFunction · 0.85

Calls 8

InvalidArgumentFunction · 0.85
valueMethod · 0.45
indexMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected