Unverified Commit 4db10d86 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

factor out .size() checks in GetDataType() (#4541)



* factor out .size() checks in GetDataType()

* Update src/io/parser.cpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
parent 4e18c60b
...@@ -184,7 +184,8 @@ DataType GetDataType(const char* filename, bool header, ...@@ -184,7 +184,8 @@ DataType GetDataType(const char* filename, bool header,
int tab_cnt = 0; int tab_cnt = 0;
int colon_cnt = 0; int colon_cnt = 0;
GetStatistic(lines[0].c_str(), &comma_cnt, &tab_cnt, &colon_cnt); GetStatistic(lines[0].c_str(), &comma_cnt, &tab_cnt, &colon_cnt);
if (lines.size() == 1) { size_t num_lines = lines.size();
if (num_lines == 1) {
if (colon_cnt > 0) { if (colon_cnt > 0) {
type = DataType::LIBSVM; type = DataType::LIBSVM;
} else if (tab_cnt > 0) { } else if (tab_cnt > 0) {
...@@ -192,7 +193,7 @@ DataType GetDataType(const char* filename, bool header, ...@@ -192,7 +193,7 @@ DataType GetDataType(const char* filename, bool header,
} else if (comma_cnt > 0) { } else if (comma_cnt > 0) {
type = DataType::CSV; type = DataType::CSV;
} }
} else if (lines.size() > 1) { } else {
int comma_cnt2 = 0; int comma_cnt2 = 0;
int tab_cnt2 = 0; int tab_cnt2 = 0;
int colon_cnt2 = 0; int colon_cnt2 = 0;
...@@ -206,7 +207,7 @@ DataType GetDataType(const char* filename, bool header, ...@@ -206,7 +207,7 @@ DataType GetDataType(const char* filename, bool header,
} }
if (type == DataType::TSV || type == DataType::CSV) { if (type == DataType::TSV || type == DataType::CSV) {
// valid the type // valid the type
for (size_t i = 2; i < lines.size(); ++i) { for (size_t i = 2; i < num_lines; ++i) {
GetStatistic(lines[i].c_str(), &comma_cnt2, &tab_cnt2, &colon_cnt2); GetStatistic(lines[i].c_str(), &comma_cnt2, &tab_cnt2, &colon_cnt2);
if (type == DataType::TSV && tab_cnt2 != tab_cnt) { if (type == DataType::TSV && tab_cnt2 != tab_cnt) {
type = DataType::INVALID; type = DataType::INVALID;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment