79 const char * lbegin = begin;
80 const char * lend = lbegin;
82 while ((lbegin != end) && (*lbegin ==
'\n' || *lbegin ==
'\r')) ++lbegin;
83 while (lbegin != end) {
85 this->IgnoreUTF8BOM(&lbegin, &end);
87 while (lend != end && *lend !=
'\n' && *lend !=
'\r') ++lend;
89 const char* p = lbegin;
92 real_t weight = std::numeric_limits<real_t>::quiet_NaN();
98 if (std::is_same<DType, real_t>::value) {
101 }
else if (std::is_same<DType, int32_t>::value) {
102 v =
static_cast<int32_t
>(strtoll(p, &endptr, 0));
104 }
else if (std::is_same<DType, int64_t>::value) {
105 v =
static_cast<int64_t
>(strtoll(p, &endptr, 0));
108 LOG(FATAL) <<
"Only float32, int32, and int64 are supported for the time being";
111 if (column_index == param_.label_column) {
112 out->label.push_back(v);
113 }
else if (std::is_same<DType, real_t>::value
114 && column_index == param_.weight_column) {
117 if (std::distance(p,
static_cast<char const*
>(endptr)) != 0) {
118 out->value.push_back(v);
119 out->index.push_back(idx++);
124 p = (endptr >= lend) ? lend : endptr;
126 while (*p != param_.delimiter[0] && p != lend) ++p;
127 if (p == lend && idx == 0) {
128 LOG(FATAL) <<
"Delimiter \'" << param_.delimiter <<
"\' is not found in the line. "
129 <<
"Expected \'" << param_.delimiter
130 <<
"\' as the delimiter to separate fields.";
135 while ((*lend ==
'\n' || *lend ==
'\r') && lend != end) ++lend;
137 if (!std::isnan(weight)) {
138 out->weight.push_back(weight);
140 out->offset.push_back(out->index.size());
142 CHECK(out->label.size() == 0 || out->label.size() + 1 == out->offset.size());
143 CHECK(out->weight.size() == 0 || out->weight.size() + 1 == out->offset.size());