MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / CSVParser

Class CSVParser

python-package/compile/src/io/parser.hpp:18–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16namespace LightGBM {
17
18class CSVParser: public Parser {
19 public:
20 explicit CSVParser(int label_idx, int total_columns)
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);
48 }
49
50 private:
51 int label_idx_ = 0;
52 int total_columns_ = -1;
53};
54
55class TSVParser: public Parser {
56 public:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected