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

Function FillAndCopyVarLen

tensorflow/core/util/example_proto_fast_parsing.cc:925–965  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

923
924template <typename T>
925void FillAndCopyVarLen(
926 const int d, const size_t num_elements,
927 const size_t num_elements_per_minibatch, const Config& config,
928 const std::vector<std::vector<SparseBuffer>>& varlen_dense_buffers,
929 Tensor* values) {
930 const Tensor& default_value = config.dense[d].default_value;
931
932 // Copy-fill the tensors (creating the zero/fill-padding)
933 std::fill(values->flat<T>().data(), values->flat<T>().data() + num_elements,
934 default_value.flat<T>()(0));
935
936 // Data is [batch_size, max_num_elements, data_stride_size]
937 // and num_elements_per_minibatch = max_num_elements * data_stride_size
938 auto data = values->flat<T>().data();
939
940 // Iterate over minibatch elements
941 for (size_t i = 0; i < varlen_dense_buffers.size(); ++i) {
942 const SparseBuffer& buffer = varlen_dense_buffers[i][d];
943 // Number of examples being stored in this buffer
944 const auto& end_indices = buffer.example_end_indices;
945 const size_t examples_in_buffer = end_indices.size();
946 // const size_t stride_size = config.dense[d].elements_per_stride;
947
948 const auto& list = GetListFromBuffer<T>(buffer);
949 auto list_ptr = list.begin();
950
951 size_t elements_tally = 0;
952 // Iterate through all the examples stored in this buffer.
953 for (size_t j = 0; j < examples_in_buffer; ++j) {
954 // Number of elements stored for this example.
955 const size_t num_elems = end_indices[j] - elements_tally;
956 CopyOrMoveBlock(list_ptr, list_ptr + num_elems, data);
957 // Move forward this many elements in the varlen buffer.
958 list_ptr += num_elems;
959 // Move forward to the next minibatch entry in the values output.
960 data += num_elements_per_minibatch;
961 elements_tally = end_indices[j];
962 }
963 DCHECK(elements_tally == list.size());
964 }
965}
966
967// Thin vector like interface wrapper around a Tensor. This enable us to
968// directly populate a tensor during parsing instead of having to first create a

Callers

nothing calls this directly

Calls 5

CopyOrMoveBlockFunction · 0.85
fillFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected