Skip to content

Commit

Permalink
use constexpr instead of define / use pragma once
Browse files Browse the repository at this point in the history
Summary: See title.

Reviewed By: wickedfoo

Differential Revision: D5559236

fbshipit-source-id: 932c1e548a31c2defb4ab20c4c897b27ab4a55f0
  • Loading branch information
cpuhrsch authored and facebook-github-bot committed Nov 30, 2017
1 parent 520b59d commit 8ca5bf0
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 64 deletions.
36 changes: 16 additions & 20 deletions src/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_ARGS_H
#define FASTTEXT_ARGS_H
#pragma once

#include <istream>
#include <ostream>
Expand All @@ -17,8 +16,8 @@

namespace fasttext {

enum class model_name : int {cbow=1, sg, sup};
enum class loss_name : int {hs=1, ns, softmax};
enum class model_name : int { cbow = 1, sg, sup };
enum class loss_name : int { hs = 1, ns, softmax };

class Args {
protected:
Expand Down Expand Up @@ -50,22 +49,19 @@ class Args {
std::string pretrainedVectors;
int saveOutput;

bool qout;
bool retrain;
bool qnorm;
size_t cutoff;
size_t dsub;
bool qout;
bool retrain;
bool qnorm;
size_t cutoff;
size_t dsub;

void parseArgs(const std::vector<std::string>& args);
void printHelp();
void printBasicHelp();
void printDictionaryHelp();
void printTrainingHelp();
void printQuantizationHelp();
void save(std::ostream&);
void load(std::istream&);
void parseArgs(const std::vector<std::string>& args);
void printHelp();
void printBasicHelp();
void printDictionaryHelp();
void printTrainingHelp();
void printQuantizationHelp();
void save(std::ostream&);
void load(std::istream&);
};

}

#endif
5 changes: 1 addition & 4 deletions src/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_DICTIONARY_H
#define FASTTEXT_DICTIONARY_H
#pragma once

#include <vector>
#include <string>
Expand Down Expand Up @@ -108,5 +107,3 @@ class Dictionary {
};

}

#endif
3 changes: 3 additions & 0 deletions src/fasttext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace fasttext {

constexpr int32_t FASTTEXT_VERSION = 12; /* Version 1b */
constexpr int32_t FASTTEXT_FILEFORMAT_MAGIC_INT32 = 793712314;

FastText::FastText() : quant_(false) {}

void FastText::addInputVector(Vector& vec, int32_t ind) const {
Expand Down
10 changes: 2 additions & 8 deletions src/fasttext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_FASTTEXT_H
#define FASTTEXT_FASTTEXT_H

#define FASTTEXT_VERSION 12 /* Version 1b */
#define FASTTEXT_FILEFORMAT_MAGIC_INT32 793712314
#pragma once

#include <time.h>

Expand Down Expand Up @@ -110,6 +106,4 @@ class FastText {
int getDimension() const;
bool isQuant() const;
};

} // namespace fasttext
#endif
}
5 changes: 1 addition & 4 deletions src/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_MATRIX_H
#define FASTTEXT_MATRIX_H
#pragma once

#include <cstdint>
#include <istream>
Expand Down Expand Up @@ -53,5 +52,3 @@ class Matrix {
};

}

#endif
4 changes: 4 additions & 0 deletions src/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

namespace fasttext {

constexpr int32_t SIGMOID_TABLE_SIZE = 512;
constexpr int32_t MAX_SIGMOID = 8;
constexpr int32_t LOG_TABLE_SIZE = 512;

Model::Model(std::shared_ptr<Matrix> wi,
std::shared_ptr<Matrix> wo,
std::shared_ptr<Args> args,
Expand Down
9 changes: 1 addition & 8 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_MODEL_H
#define FASTTEXT_MODEL_H
#pragma once

#include <vector>
#include <random>
Expand All @@ -21,10 +20,6 @@
#include "qmatrix.h"
#include "real.h"

#define SIGMOID_TABLE_SIZE 512
#define MAX_SIGMOID 8
#define LOG_TABLE_SIZE 512

namespace fasttext {

struct Node {
Expand Down Expand Up @@ -107,5 +102,3 @@ class Model {
};

}

#endif
5 changes: 1 addition & 4 deletions src/productquantizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_PRODUCT_QUANTIZER_H
#define FASTTEXT_PRODUCT_QUANTIZER_H
#pragma once

#include <cstring>
#include <istream>
Expand Down Expand Up @@ -63,5 +62,3 @@ class ProductQuantizer {
};

}

#endif
5 changes: 1 addition & 4 deletions src/qmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_QMATRIX_H
#define FASTTEXT_QMATRIX_H
#pragma once

#include <cstdint>
#include <istream>
Expand Down Expand Up @@ -61,5 +60,3 @@ class QMatrix {
};

}

#endif
5 changes: 1 addition & 4 deletions src/real.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_REAL_H
#define FASTTEXT_REAL_H
#pragma once

namespace fasttext {

typedef float real;

}

#endif
5 changes: 1 addition & 4 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_UTILS_H
#define FASTTEXT_UTILS_H
#pragma once

#include <fstream>

Expand All @@ -29,5 +28,3 @@ namespace utils {
}

}

#endif
5 changes: 1 addition & 4 deletions src/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#ifndef FASTTEXT_VECTOR_H
#define FASTTEXT_VECTOR_H
#pragma once

#include <cstdint>
#include <ostream>
Expand Down Expand Up @@ -49,5 +48,3 @@ class Vector {
std::ostream& operator<<(std::ostream&, const Vector&);

}

#endif

0 comments on commit 8ca5bf0

Please sign in to comment.