Skip to content

Commit bb2ea08

Browse files
kahnefacebook-github-bot
authored andcommitted
Make args dump function const / removed code in fasttext.cc
Summary: Make args dump function const / removed code in fasttext.cc Reviewed By: EdouardGrave Differential Revision: D6619928 fbshipit-source-id: 99152caa6f5799248bfcc6ae39a6ede29963765a
1 parent 9210895 commit bb2ea08

File tree

5 files changed

+20
-41
lines changed

5 files changed

+20
-41
lines changed

src/args.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Args::Args() {
4545
dsub = 2;
4646
}
4747

48-
std::string Args::lossToString(loss_name ln) {
48+
std::string Args::lossToString(loss_name ln) const {
4949
switch (ln) {
5050
case loss_name::hs:
5151
return "hs";
@@ -57,15 +57,15 @@ std::string Args::lossToString(loss_name ln) {
5757
return "Unknown loss!"; // should never happen
5858
}
5959

60-
std::string Args::boolToString(bool b) {
60+
std::string Args::boolToString(bool b) const {
6161
if (b) {
6262
return "true";
6363
} else {
6464
return "false";
6565
}
6666
}
6767

68-
std::string Args::modelToString(model_name mn) {
68+
std::string Args::modelToString(model_name mn) const {
6969
switch (mn) {
7070
case model_name::cbow:
7171
return "cbow";
@@ -274,7 +274,7 @@ void Args::load(std::istream& in) {
274274
in.read((char*) &(t), sizeof(double));
275275
}
276276

277-
void Args::dump(std::ostream& out) {
277+
void Args::dump(std::ostream& out) const {
278278
out << "dim" << " " << dim << std::endl;
279279
out << "ws" << " " << ws << std::endl;
280280
out << "epoch" << " " << epoch << std::endl;

src/args.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ enum class loss_name : int { hs = 1, ns, softmax };
2121

2222
class Args {
2323
protected:
24-
std::string lossToString(loss_name);
25-
std::string boolToString(bool);
26-
std::string modelToString(model_name);
24+
std::string lossToString(loss_name) const;
25+
std::string boolToString(bool) const;
26+
std::string modelToString(model_name) const;
2727

2828
public:
2929
Args();
@@ -64,6 +64,6 @@ class Args {
6464
void printQuantizationHelp();
6565
void save(std::ostream&);
6666
void load(std::istream&);
67-
void dump(std::ostream&);
67+
void dump(std::ostream&) const;
6868
};
6969
}

src/fasttext.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -710,28 +710,4 @@ bool FastText::isQuant() const {
710710
return quant_;
711711
}
712712

713-
void FastText::dumpArgs() const {
714-
args_->dump(std::cout);
715-
}
716-
717-
void FastText::dumpDict() const {
718-
dict_->dump(std::cout);
719-
}
720-
721-
void FastText::dumpInput() const {
722-
if (quant_) {
723-
std::cerr << "Not supported for quantized models." << std::endl;
724-
} else {
725-
input_->dump(std::cout);
726-
}
727-
}
728-
729-
void FastText::dumpOutput() const {
730-
if (quant_) {
731-
std::cerr << "Not supported for quantized models." << std::endl;
732-
} else {
733-
output_->dump(std::cout);
734-
}
735-
}
736-
737713
}

src/fasttext.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,5 @@ class FastText {
111111
void loadVectors(std::string);
112112
int getDimension() const;
113113
bool isQuant() const;
114-
115-
void dumpArgs() const;
116-
void dumpDict() const;
117-
void dumpInput() const;
118-
void dumpOutput() const;
119114
};
120115
}

src/main.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,21 @@ void dump(const std::vector<std::string>& args) {
283283
FastText fasttext;
284284
fasttext.loadModel(modelPath);
285285
if (option == "args") {
286-
fasttext.dumpArgs();
286+
fasttext.getArgs().dump(std::cout);
287287
} else if (option == "dict") {
288-
fasttext.dumpDict();
288+
fasttext.getDictionary()->dump(std::cout);
289289
} else if (option == "input") {
290-
fasttext.dumpInput();
290+
if (fasttext.isQuant()) {
291+
std::cerr << "Not supported for quantized models." << std::endl;
292+
} else {
293+
fasttext.getInputMatrix()->dump(std::cout);
294+
}
291295
} else if (option == "output") {
292-
fasttext.dumpOutput();
296+
if (fasttext.isQuant()) {
297+
std::cerr << "Not supported for quantized models." << std::endl;
298+
} else {
299+
fasttext.getOutputMatrix()->dump(std::cout);
300+
}
293301
} else {
294302
printDumpUsage();
295303
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)