Skip to content

Commit

Permalink
r cmd check - replace exit with Rcpp::stop and move Rcpp.h down
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijffels committed Feb 19, 2024
1 parent 28e5dd7 commit bb59531
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Starspace/src/utils/args.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <Rcpp.h>
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -15,6 +14,7 @@
#include <string>
#include <cstring>
#include <assert.h>
#include <Rcpp.h>

using namespace std;

Expand Down Expand Up @@ -72,7 +72,7 @@ void Args::parseArgs(int argc, char** argv) {
if (argc <= 1) {
Rcpp::Rcerr << "Usage: need to specify whether it is train or test.\n";
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
if (strcmp(argv[1], "train") == 0) {
isTrain = true;
Expand All @@ -81,18 +81,18 @@ void Args::parseArgs(int argc, char** argv) {
} else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-help") == 0) {
Rcpp::Rcerr << "Here is the help! Usage:" << std::endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
} else {
Rcpp::Rcerr << "Usage: the first argument should be either train or test.\n";
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
int i = 2;
while (i < argc) {
if (argv[i][0] != '-') {
Rcpp::Rcout << "Provided argument without a dash! Usage:" << endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}

// handling "--"
Expand All @@ -103,7 +103,7 @@ void Args::parseArgs(int argc, char** argv) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
Rcpp::Rcerr << "Here is the help! Usage:" << std::endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
} else if (strcmp(argv[i], "-trainFile") == 0) {
trainFile = string(argv[i + 1]);
} else if (strcmp(argv[i], "-validationFile") == 0) {
Expand Down Expand Up @@ -195,21 +195,21 @@ void Args::parseArgs(int argc, char** argv) {
} else {
Rcpp::Rcerr << "Unknown argument: " << argv[i] << std::endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
i += 2;
}
if (isTrain) {
if (trainFile.empty() || model.empty()) {
Rcpp::Rcerr << "Empty train file or output model path." << endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
} else {
if (testFile.empty() || model.empty()) {
Rcpp::Rcerr << "Empty test file or model path." << endl;
printHelp();
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
}
// check for trainMode
Expand All @@ -221,22 +221,22 @@ void Args::parseArgs(int argc, char** argv) {
Rcpp::Rcerr << "trainMode 3: at training time, one label from RHS is picked as true label and another label from RHS is picked as LHS.\n";
Rcpp::Rcerr << "trainMode 4: at training time, the first label from RHS is picked as LHS and the second one picked as true label.\n";
Rcpp::Rcerr << "trainMode 5: continuous bag of words training.\n";
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
// check for loss type
if (!(loss == "hinge" || loss == "softmax")) {
Rcpp::Rcerr << "Unsupported loss type: " << loss << endl;
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
// check for similarity type
if (!(similarity == "cosine" || similarity == "dot")) {
Rcpp::Rcerr << "Unsupported similarity type. Should be either dot or cosine.\n";
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
// check for file format
if (!(fileFormat == "fastText" || fileFormat == "labelDoc")) {
Rcpp::Rcerr << "Unsupported file format type. Should be either fastText or labelDoc.\n";
exit(EXIT_FAILURE);
Rcpp::stop("Incorrect Starspace usage");
}
}

Expand Down

0 comments on commit bb59531

Please sign in to comment.