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

Function PrintOneDimV2

tensorflow/core/framework/tensor.cc:1126–1167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124// Print from left dim to right dim recursively.
1125template <typename T>
1126void PrintOneDimV2(int dim_index, const gtl::InlinedVector<int64, 4>& shape,
1127 int64 num_elts_at_ends, int num_dims, const T* data,
1128 int64 data_index, string* result) {
1129 // We have recursed beyond all the dimensions into a single element
1130 // of the tensor.
1131 if (dim_index == num_dims) {
1132 strings::StrAppend(result, PrintOneElement(data[data_index], true));
1133 return;
1134 }
1135
1136 strings::StrAppend(result, "[");
1137 int64 element_count = shape[dim_index];
1138 int64 start_of_end =
1139 std::max(num_elts_at_ends, element_count - num_elts_at_ends);
1140
1141 // Loop every element of one dim.
1142 int64 elements_per_iter = 1;
1143 for (int i = dim_index + 1; i < num_dims; i++) {
1144 elements_per_iter *= shape[i];
1145 }
1146 for (int64 i = 0; (i < num_elts_at_ends) && (i < element_count); i++) {
1147 if (i > 0) {
1148 PrintDimSpacing(dim_index, num_dims, result);
1149 }
1150
1151 // As for each element, print the sub-dim.
1152 PrintOneDimV2(dim_index + 1, shape, num_elts_at_ends, num_dims, data,
1153 data_index + elements_per_iter * i, result);
1154 }
1155 if (element_count > 2 * num_elts_at_ends) {
1156 PrintDimSpacing(dim_index, num_dims, result);
1157 strings::StrAppend(result, "...");
1158 }
1159 for (int64 i = start_of_end; i < element_count; i++) {
1160 // As for each element, print the sub-dim.
1161 PrintDimSpacing(dim_index, num_dims, result);
1162 PrintOneDimV2(dim_index + 1, shape, num_elts_at_ends, num_dims, data,
1163 data_index + elements_per_iter * i, result);
1164 }
1165
1166 strings::StrAppend(result, "]");
1167}
1168
1169template <typename T>
1170string SummarizeArray(int64 limit, int64 num_elts,

Callers 1

SummarizeArrayFunction · 0.85

Calls 4

PrintOneElementFunction · 0.85
PrintDimSpacingFunction · 0.85
StrAppendFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected