| 86 | } |
| 87 | |
| 88 | static TVector<float> ReadGroupWeights( |
| 89 | const TPathWithScheme& filePath, |
| 90 | TConstArrayRef<TGroupId> groupIds, |
| 91 | ui64 docCount, |
| 92 | TDatasetSubset loadSubset |
| 93 | ) { |
| 94 | Y_UNUSED(loadSubset); |
| 95 | CB_ENSURE(groupIds.size() == docCount, "GroupId count should correspond to object count."); |
| 96 | THolder<ILineDataReader> reader = GetLineDataReader(filePath); |
| 97 | TString line; |
| 98 | THashMap<TGroupId, float> groupWeightsByGroupId; |
| 99 | for (size_t lineNumber = 0; reader->ReadLine(&line); lineNumber++) { |
| 100 | try { |
| 101 | TVector<TString> tokens = StringSplitter(line).Split('\t'); |
| 102 | CB_ENSURE(tokens.size() == 2, |
| 103 | "Each line should have two columns. This line has " << tokens.size() |
| 104 | ); |
| 105 | const TGroupId groupId = CalcGroupIdFor(tokens[0]); |
| 106 | float groupWeight = 1.0f; |
| 107 | CB_ENSURE( |
| 108 | TryFromString(tokens[1], groupWeight), |
| 109 | "Invalid group weight: cannot parse as float (" << tokens[1] << ')' |
| 110 | ); |
| 111 | CB_ENSURE(!groupWeightsByGroupId.contains(groupId), "GroupId at line " << lineNumber << " is repeated in group weights file"); |
| 112 | groupWeightsByGroupId[groupId] = groupWeight; |
| 113 | } catch (const TCatBoostException& e) { |
| 114 | throw TCatBoostException() << "Incorrect file with group weights. Invalid line number #" |
| 115 | << lineNumber << ": " << e.what(); |
| 116 | } |
| 117 | } |
| 118 | TVector<float> groupWeights; |
| 119 | groupWeights.reserve(docCount); |
| 120 | for (auto rowIdx : xrange(groupIds.size())) { |
| 121 | CB_ENSURE(groupWeightsByGroupId.contains(groupIds[rowIdx]), "GroupId from row " << rowIdx << " in dataset is not found in group weights file"); |
| 122 | groupWeights.emplace_back(groupWeightsByGroupId.at(groupIds[rowIdx])); |
| 123 | } |
| 124 | |
| 125 | return groupWeights; |
| 126 | } |
| 127 | |
| 128 | static TVector<ui64> ReadGroupTimestamps( |
| 129 | const TPathWithScheme& filePath, |
no test coverage detected