| 160 | |
| 161 | template<typename V> |
| 162 | bool StreamReader<V>::readMatricesFromText() { // uint32 num_ex, MatrixPtrList<V>* mat) { |
| 163 | uint32 num_read = 0; |
| 164 | while (num_read < num_examples_ && !reach_data_end_) { |
| 165 | while (true) { |
| 166 | // read a line |
| 167 | char* result = data_file_->readLine(line_, kMaxLineLength_); |
| 168 | if (result != nullptr) { |
| 169 | // Chop the last linefeed if present. |
| 170 | int len = strlen(result); |
| 171 | if (len > 0 && result[len - 1] == '\n') { // Linefeed. |
| 172 | result[--len] = '\0'; |
| 173 | } |
| 174 | if (len > 0 && result[len - 1] == '\r') { // Carriage return. |
| 175 | result[--len] = '\0'; |
| 176 | } |
| 177 | Example ex; |
| 178 | if (!text_parser_.toProto(result, &ex)) continue; |
| 179 | parseExample(ex, num_read); |
| 180 | ++ num_read; |
| 181 | break; |
| 182 | } else { |
| 183 | if (!openNextFile()) break; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | // LL << num_read << " " << reach_data_end_; |
| 188 | fillMatrices(); |
| 189 | return !reach_data_end_; |
| 190 | } |
| 191 | |
| 192 | template<typename V> |
| 193 | bool StreamReader<V>::readMatrices( |