| 1071 | // Print from left dim to right dim recursively. |
| 1072 | template <typename T> |
| 1073 | void PrintOneDim(int dim_index, const gtl::InlinedVector<int64, 4>& shape, |
| 1074 | int64 limit, int shape_size, const T* data, int64* data_index, |
| 1075 | string* result) { |
| 1076 | if (*data_index >= limit) return; |
| 1077 | int64 element_count = shape[dim_index]; |
| 1078 | // We have reached the right-most dimension of the tensor. |
| 1079 | if (dim_index == shape_size - 1) { |
| 1080 | for (int64 i = 0; i < element_count; i++) { |
| 1081 | if (*data_index >= limit) { |
| 1082 | // If not enough elements has been printed, append "...". |
| 1083 | if (dim_index != 0) { |
| 1084 | strings::StrAppend(result, "..."); |
| 1085 | } |
| 1086 | return; |
| 1087 | } |
| 1088 | if (i > 0) strings::StrAppend(result, " "); |
| 1089 | strings::StrAppend(result, PrintOneElement(data[(*data_index)++], false)); |
| 1090 | } |
| 1091 | return; |
| 1092 | } |
| 1093 | // Loop every element of one dim. |
| 1094 | for (int64 i = 0; i < element_count; i++) { |
| 1095 | bool flag = false; |
| 1096 | if (*data_index < limit) { |
| 1097 | strings::StrAppend(result, "["); |
| 1098 | flag = true; |
| 1099 | } |
| 1100 | // As for each element, print the sub-dim. |
| 1101 | PrintOneDim(dim_index + 1, shape, limit, shape_size, data, data_index, |
| 1102 | result); |
| 1103 | if (*data_index < limit || flag) { |
| 1104 | strings::StrAppend(result, "]"); |
| 1105 | flag = false; |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // Appends the spacing between elements for a given dim onto a result string |
| 1111 | void PrintDimSpacing(int dim_index, int num_dims, string* result) { |
no test coverage detected