Skip to content

Commit

Permalink
Add labels vector processing, that prevent an segfault if label index…
Browse files Browse the repository at this point in the history
…es are not sorted
  • Loading branch information
mwydmuch committed Jan 10, 2025
1 parent 824ec68 commit 5e9ae56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/read_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ bool DataReader::readData(SRMatrix& labels, SRMatrix& features, Args& args, int
continue;
}

if(args.processData) processFeaturesVector(lFeatures, args.norm, args.hash, args.featuresThreshold);
if(args.processData) {
processFeaturesVector(lFeatures, args.norm, args.hash, args.featuresThreshold);
processLabelsVector(lLabels);
}

labels.appendRow(lLabels);
features.appendRow(lFeatures);
Expand Down Expand Up @@ -193,4 +196,9 @@ void DataReader::processFeaturesVector(std::vector<IRVPair> &lFeatures, bool nor
if (!std::is_sorted(lFeatures.begin(), lFeatures.end(), IRVPairIndexComp())) sort(lFeatures.begin(), lFeatures.end(), IRVPairIndexComp());
}

void DataReader::processLabelsVector(std::vector<IRVPair> &lLabels) {
// Check if it requires sorting
if (!std::is_sorted(lLabels.begin(), lLabels.end(), IRVPairIndexComp())) sort(lLabels.begin(), lLabels.end(), IRVPairIndexComp());
}


1 change: 1 addition & 0 deletions src/read_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DataReader {

static void prepareFeaturesVector(std::vector<IRVPair> &lFeatures, Real bias = 1.0);
static void processFeaturesVector(std::vector<IRVPair> &lFeatures, bool norm = true, size_t hashSize = 0, Real featuresThreshold = 0);
static void processLabelsVector(std::vector<IRVPair> &lLabels);

private:
std::ifstream in;
Expand Down

0 comments on commit 5e9ae56

Please sign in to comment.