| 106 | */ |
| 107 | template <typename T> |
| 108 | void ReadData(const std::vector<char>& buffer, |
| 109 | const unsigned int dataStart, |
| 110 | const DataType& tensorType, |
| 111 | std::vector<T>& results) |
| 112 | { |
| 113 | unsigned int index = dataStart; |
| 114 | while (index < buffer.size()) |
| 115 | { |
| 116 | std::string elementString; |
| 117 | // Extract into a string until the next space. |
| 118 | while (index < buffer.size() && buffer[index] != ' ') |
| 119 | { |
| 120 | elementString.push_back(buffer[index]); |
| 121 | index++; |
| 122 | } |
| 123 | if (!elementString.empty()) |
| 124 | { |
| 125 | switch (tensorType) |
| 126 | { |
| 127 | case DataType::Float32: { |
| 128 | results.push_back(static_cast<T>(std::stof(elementString))); |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | case DataType::Signed32: { |
| 133 | results.push_back(static_cast<T>(std::stoi(elementString))); |
| 134 | break; |
| 135 | } |
| 136 | case DataType::QSymmS8: |
| 137 | case DataType::QAsymmS8: { |
| 138 | results.push_back(static_cast<T>(elementString[0])); |
| 139 | break; |
| 140 | } |
| 141 | case DataType::QAsymmU8: { |
| 142 | results.push_back(static_cast<T>(elementString[0])); |
| 143 | break; |
| 144 | } |
| 145 | case DataType::Float16: |
| 146 | case DataType::QSymmS16: |
| 147 | case DataType::BFloat16: |
| 148 | case DataType::Boolean: |
| 149 | case DataType::Signed64: |
| 150 | default: { |
| 151 | LogAndThrow("Unsupported DataType"); |
| 152 | } |
| 153 | } |
| 154 | // Finally, skip the space we know is there. |
| 155 | index++; |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | if (index < buffer.size()) |
| 160 | { |
| 161 | index++; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
no test coverage detected