| 21 | :label_idx_(label_idx), total_columns_(total_columns) { |
| 22 | } |
| 23 | inline void ParseOneLine(const char* str, |
| 24 | std::vector<std::pair<int, double>>* out_features, double* out_label) const override { |
| 25 | int idx = 0; |
| 26 | double val = 0.0f; |
| 27 | int offset = 0; |
| 28 | *out_label = 0.0f; |
| 29 | while (*str != '\0') { |
| 30 | str = Common::Atof(str, &val); |
| 31 | if (idx == label_idx_) { |
| 32 | *out_label = val; |
| 33 | offset = -1; |
| 34 | } else if (std::fabs(val) > kZeroThreshold || std::isnan(val)) { |
| 35 | out_features->emplace_back(idx + offset, val); |
| 36 | } |
| 37 | ++idx; |
| 38 | if (*str == ',') { |
| 39 | ++str; |
| 40 | } else if (*str != '\0') { |
| 41 | Log::Fatal("Input format error when parsing as CSV"); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | inline int NumFeatures() const override { |
| 47 | return total_columns_ - (label_idx_ >= 0); |
no test coverage detected