| 26 | } |
| 27 | |
| 28 | void NCB::TDsvFlatPairsLoader::Do(IDatasetVisitor* visitor) { |
| 29 | THolder<ILineDataReader> reader = GetLineDataReader(Args.Path, NCB::TDsvFormatOptions(), /*keepLineOrder*/false); |
| 30 | |
| 31 | const auto approxmatePairsCount = reader->GetDataLineCount(/*estimate*/true); |
| 32 | TVector<TPair> pairs; |
| 33 | pairs.reserve(approxmatePairsCount); |
| 34 | TString line; |
| 35 | ui64 lineNumber; |
| 36 | THPTimer progressTimer; |
| 37 | ui64 progressIndex = 0; |
| 38 | while (reader->ReadLine(&line, &lineNumber)) { |
| 39 | if (progressTimer.Passed() > 60/*seconds*/) { |
| 40 | if (progressIndex < approxmatePairsCount) { |
| 41 | CATBOOST_DEBUG_LOG << "Last minute status: " << progressIndex / CeilDiv<ui32>(approxmatePairsCount, 100) << "% pairs loaded" << Endl; |
| 42 | } else { |
| 43 | CATBOOST_DEBUG_LOG << "Last minute status: " << progressIndex << " pairs loaded" << Endl; |
| 44 | } |
| 45 | progressTimer.Reset(); |
| 46 | } |
| 47 | TVector<TString> tokens = StringSplitter(line).Split('\t'); |
| 48 | if (tokens.empty()) { |
| 49 | continue; |
| 50 | } |
| 51 | try { |
| 52 | CB_ENSURE(tokens.ysize() == 2 || tokens.ysize() == 3, |
| 53 | "Each line should have two or three columns. This line has " << tokens.size() |
| 54 | ); |
| 55 | TPair pair; |
| 56 | |
| 57 | size_t tokenIdx = 0; |
| 58 | auto parseIdFunc = [&](TStringBuf description, ui32* id) { |
| 59 | CB_ENSURE( |
| 60 | TryFromString(tokens[tokenIdx], *id), |
| 61 | "Invalid " << description << " index: cannot parse as nonnegative index (" |
| 62 | << tokens[tokenIdx] << ')' |
| 63 | ); |
| 64 | *id -= Args.DatasetSubset.Range.Begin; |
| 65 | ++tokenIdx; |
| 66 | }; |
| 67 | parseIdFunc(TStringBuf("Winner"), &pair.WinnerId); |
| 68 | parseIdFunc(TStringBuf("Loser"), &pair.LoserId); |
| 69 | |
| 70 | if (tokens.ysize() == 3) { |
| 71 | CB_ENSURE( |
| 72 | TryFromString(tokens[2], pair.Weight), |
| 73 | "Invalid weight: cannot parse as float (" << tokens[2] << ')' |
| 74 | ); |
| 75 | } else { |
| 76 | pair.Weight = 1.0f; |
| 77 | } |
| 78 | if (pair.WinnerId < Args.DatasetSubset.GetSize() && |
| 79 | pair.LoserId < Args.DatasetSubset.GetSize()) |
| 80 | { |
| 81 | pairs.push_back(std::move(pair)); |
| 82 | } else { |
| 83 | CB_ENSURE( |
| 84 | pair.WinnerId >= Args.DatasetSubset.GetSize() && |
| 85 | pair.LoserId >= Args.DatasetSubset.GetSize(), |
nothing calls this directly
no test coverage detected