facebookresearch / StarSpace

Learning embeddings for classification, retrieval and ranking.
MIT License
3.94k stars 531 forks source link

compiler warnings #181

Closed jwijffels closed 6 years ago

jwijffels commented 6 years ago

Hello, I would like to publish one of these days the R package which I've created wrapping StarSpace to CRAN. CRAN is pretty picky about compiler warnings and does not allow to e.g. compile with the following -Wno-sign-compare -Wno-unused-value -Wno-unused-variable -Wno-unused-but-set-variable. Would it be possible to solve the compiler warnings shown below. That would be great!

c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/utils/args.cpp -o Starspace/src/utils/args.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/utils/normalize.cpp -o Starspace/src/utils/normalize.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/utils/utils.cpp -o Starspace/src/utils/utils.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/data.cpp -o Starspace/src/data.o
Starspace/src/data.cpp: In member function 'virtual void starspace::InternDataHandler::convert(const starspace::ParseResults&, starspace::ParseResults&) const':
Starspace/src/data.cpp:104:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < example.RHSTokens.size(); i++) {
                         ^
Starspace/src/data.cpp:106:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == idx) {
               ^
Starspace/src/data.cpp:116:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < example.RHSTokens.size(); i++) {
                         ^
Starspace/src/data.cpp:118:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == idx) {
               ^
Starspace/src/data.cpp:131:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       } while (idx2 == idx);
                     ^
Starspace/src/data.cpp: In member function 'void starspace::InternDataHandler::getWordExamples(const std::vector<std::pair<int, float> >&, std::vector<starspace::ParseResults>&) const':
Starspace/src/data.cpp:148:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int widx = 0; widx < doc.size(); widx++) {
                           ^
Starspace/src/data.cpp:154:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          i < min(size_t(widx + args_->ws), doc.size()); i++) {
            ^
Starspace/src/data.cpp: In member function 'void starspace::InternDataHandler::getRandomWord(std::vector<std::pair<int, float> >&)':
Starspace/src/data.cpp:221:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (word_iter_ >= word_negatives_.size()) {
                  ^
Starspace/src/data.cpp: In member function 'virtual void starspace::InternDataHandler::getRandomRHS(std::vector<std::pair<int, float> >&) const':
Starspace/src/data.cpp:250:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ex.RHSTokens.size(); i++) {
                       ^
In file included from Starspace/src/data.cpp:12:0:
Starspace/src/utils/utils.h: In instantiation of 'starspace::foreach_line(const String&, Lambda, int)::<lambda(std::ifstream&)> [with String = std::basic_string<char>; Lambda = starspace::InternDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>; std::ifstream = std::basic_ifstream<char>]':
Starspace/src/utils/utils.h:107:20:   required from 'struct starspace::foreach_line(const String&, Lambda, int) [with String = std::basic_string<char>; Lambda = starspace::InternDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>]::<lambda(std::ifstream&)>'
Starspace/src/utils/utils.h:111:3:   required from 'void starspace::foreach_line(const String&, Lambda, int) [with String = std::basic_string<char>; Lambda = starspace::InternDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>]'
Starspace/src/data.cpp:62:3:   required from here
Starspace/src/utils/utils.h:108:10: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
     auto pos = tellg(f);
          ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/dict.cpp -o Starspace/src/dict.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/doc_data.cpp -o Starspace/src/doc_data.o
Starspace/src/doc_data.cpp: In member function 'virtual void starspace::LayerDataHandler::convert(const starspace::ParseResults&, starspace::ParseResults&) const':
Starspace/src/doc_data.cpp:136:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < example.RHSFeatures.size(); i++) {
                         ^
Starspace/src/doc_data.cpp:137:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == idx) {
               ^
Starspace/src/doc_data.cpp:147:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < example.RHSFeatures.size(); i++) {
                         ^
Starspace/src/doc_data.cpp:148:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == idx) {
               ^
Starspace/src/doc_data.cpp:163:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       } while (idx == idx2);
                    ^
Starspace/src/doc_data.cpp: In member function 'virtual void starspace::LayerDataHandler::getRandomRHS(std::vector<std::pair<int, float> >&) const':
Starspace/src/doc_data.cpp:191:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ex.RHSFeatures.size(); i++) {
                       ^
In file included from Starspace/src/doc_data.cpp:12:0:
Starspace/src/utils/utils.h: In instantiation of 'starspace::foreach_line(const String&, Lambda, int)::<lambda(std::ifstream&)> [with String = std::basic_string<char>; Lambda = starspace::LayerDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>; std::ifstream = std::basic_ifstream<char>]':
Starspace/src/utils/utils.h:107:20:   required from 'struct starspace::foreach_line(const String&, Lambda, int) [with String = std::basic_string<char>; Lambda = starspace::LayerDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>]::<lambda(std::ifstream&)>'
Starspace/src/utils/utils.h:111:3:   required from 'void starspace::foreach_line(const String&, Lambda, int) [with String = std::basic_string<char>; Lambda = starspace::LayerDataHandler::loadFromFile(const string&, std::shared_ptr<starspace::DataParser>)::<lambda(std::string&)>]'
Starspace/src/doc_data.cpp:51:5:   required from here
Starspace/src/utils/utils.h:108:10: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
     auto pos = tellg(f);
          ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/doc_parser.cpp -o Starspace/src/doc_parser.o
Starspace/src/doc_parser.cpp: In member function 'bool starspace::LayerDataParser::parse(std::string&, std::vector<std::pair<int, float> >&, const string&)':
Starspace/src/doc_parser.cpp:46:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = start_idx; i < tokens.size(); i++) {
                             ^
Starspace/src/doc_parser.cpp: In member function 'virtual bool starspace::LayerDataParser::parse(std::string&, starspace::ParseResults&, const string&)':
Starspace/src/doc_parser.cpp:87:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = start_idx; i < parts.size(); i++) {
                             ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/model.cpp -o Starspace/src/model.o
In file included from Starspace/src/model.cpp:10:0:
Starspace/src/model.h: In static member function 'static void starspace::EmbedModel::check(const boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >&)':
Starspace/src/model.h:187:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < m.size1(); i++) {
                       ^
Starspace/src/model.h:188:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < m.size2(); j++) {
                         ^
Starspace/src/model.cpp: In function 'starspace::Real starspace::dot(starspace::Matrix<float>::Row, starspace::Matrix<float>::Row)':
Starspace/src/model.cpp:111:14: warning: unused variable 'dim' [-Wunused-variable]
   const auto dim = a.size();
              ^
Starspace/src/model.cpp: In lambda function:
Starspace/src/model.cpp:301:13: warning: unused variable 'etas' [-Wunused-variable]
         int etas = (eta - etah * 3600 - etam * 60);
             ^
Starspace/src/model.cpp:249:13: warning: unused variable 'elapsed' [-Wunused-variable]
     int64_t elapsed;
             ^
Starspace/src/model.cpp: In member function 'starspace::Real starspace::EmbedModel::train(std::shared_ptr<starspace::InternDataHandler>, int, std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> > >, int, starspace::Real, starspace::Real, bool)':
Starspace/src/model.cpp:325:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (size_t i = 0; i < numThreads; i++) {
                        ^
Starspace/src/model.cpp: In member function 'float starspace::EmbedModel::trainOne(std::shared_ptr<starspace::InternDataHandler>, const std::vector<std::pair<int, float> >&, const std::vector<std::pair<int, float> >&, std::size_t, starspace::Real, bool)':
Starspace/src/model.cpp:421:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < negSearchLimit &&
                     ^
Starspace/src/model.cpp:422:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                   negs.size() < args_->maxNegSamples; i++) {
                               ^
Starspace/src/model.cpp:397:8: warning: unused variable 'negSim' [-Wunused-variable]
   Real negSim = (std::numeric_limits<Real>::min)();
        ^
Starspace/src/model.cpp: In member function 'float starspace::EmbedModel::trainNLL(std::shared_ptr<starspace::InternDataHandler>, const std::vector<std::pair<int, float> >&, const std::vector<std::pair<int, float> >&, int32_t, starspace::Real, bool)':
Starspace/src/model.cpp:561:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < negRate.size(); i++) {
                     ^
Starspace/src/model.cpp: In member function 'void starspace::EmbedModel::loadTsvLine(std::string&, int, int, std::string)':
Starspace/src/model.cpp:699:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (pieces.size() > cols + 1) {
                     ^
Starspace/src/model.cpp:710:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (pieces.size() == cols) {
                     ^
Starspace/src/model.cpp:715:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (pieces.size() < cols + 1) {
                        ^
Starspace/src/model.cpp: In lambda function:
Starspace/src/model.cpp:798:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (size_t i = 0; i < size; i++) {
                          ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/parser.cpp -o Starspace/src/parser.o
Starspace/src/parser.cpp: In member function 'virtual void starspace::DataParser::parseForDict(std::string&, std::vector<std::basic_string<char> >&, const string&)':
Starspace/src/parser.cpp:58:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < toks.size(); i++) {
                     ^
Starspace/src/parser.cpp: In member function 'void starspace::DataParser::addNgrams(const std::vector<std::basic_string<char> >&, std::vector<std::pair<int, float> >&, int)':
Starspace/src/parser.cpp:103:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int32_t i = 0; i < hashes.size(); i++) {
                         ^
Starspace/src/parser.cpp:105:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int32_t j = i + 1; j < hashes.size() && j < i + n; j++) {
                               ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/proj.cpp -o Starspace/src/proj.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c Starspace/src/starspace.cpp -o Starspace/src/starspace.o
In file included from Starspace/src/starspace.h:18:0,
                 from Starspace/src/starspace.cpp:12:
Starspace/src/model.h: In static member function 'static void starspace::EmbedModel::check(const boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >&)':
Starspace/src/model.h:187:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < m.size1(); i++) {
                       ^
Starspace/src/model.h:188:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < m.size2(); j++) {
                         ^
Starspace/src/starspace.cpp: In member function 'void starspace::StarSpace::initFromTsv(const string&)':
Starspace/src/starspace.cpp:149:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (args_->dim != dim) {
                  ^
Starspace/src/starspace.cpp: In member function 'starspace::MatrixRow starspace::StarSpace::getNgramVector(const string&)':
Starspace/src/starspace.cpp:256:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (tokens.size() > args_->ngrams) {
                     ^
Starspace/src/starspace.cpp: In member function 'void starspace::StarSpace::predictOne(const std::vector<std::pair<int, float> >&, std::vector<std::pair<float, int> >&)':
Starspace/src/starspace.cpp:328:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < baseDocVectors_.size(); i++) {
                     ^
Starspace/src/starspace.cpp: In member function 'starspace::Metrics starspace::StarSpace::evaluateOne(const std::vector<std::pair<int, float> >&, const std::vector<std::pair<int, float> >&, std::vector<std::pair<float, int> >&, bool)':
Starspace/src/starspace.cpp:358:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < baseDocVectors_.size(); i++) {
                     ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c rcpp_textspace.cpp -o rcpp_textspace.o
In file included from ./Starspace/src/starspace.h:18:0,
                 from rcpp_textspace.cpp:2:
./Starspace/src/model.h: In static member function 'static void starspace::EmbedModel::check(const boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >&)':
./Starspace/src/model.h:187:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < m.size1(); i++) {
                       ^
./Starspace/src/model.h:188:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < m.size2(); j++) {
                         ^
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c compliance.cpp -o compliance.o
c:/Rtools/mingw_64/bin/g++  -std=c++0x -I"C:/PROGRA~1/R/R-33~1.0/include" -DNDEBUG -DSTRICT_R_HEADERS -include compliance.h -pthread -I./Starspace/src    -I"C:/Users/Jan/Documents/R/win-library/3.3/Rcpp/include" -I"C:/Users/Jan/Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o ruimtehol.dll tmp.def Starspace/src/utils/args.o Starspace/src/utils/normalize.o Starspace/src/utils/utils.o Starspace/src/data.o Starspace/src/dict.o Starspace/src/doc_data.o Starspace/src/doc_parser.o Starspace/src/model.o Starspace/src/parser.o Starspace/src/proj.o Starspace/src/starspace.o rcpp_textspace.o compliance.o RcppExports.o -pthread -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.0/bin/x64 -lR
rm -f Starspace/src/utils/args.o Starspace/src/utils/normalize.o Starspace/src/utils/utils.o Starspace/src/data.o Starspace/src/dict.o Starspace/src/doc_data.o Starspace/src/doc_parser.o Starspace/src/model.o Starspace/src/parser.o Starspace/src/proj.o Starspace/src/starspace.o rcpp_textspace.o compliance.o RcppExports.o
installing to C:/Users/Jan/AppData/Local/Temp/RtmpGq8jNq/devtools_install_1458443c4f13/ruimtehol/libs/x64
* DONE (ruimtehol)
ledw commented 6 years ago

@jwijffels Hi, thanks. Sure we can resolve that by changing from int to unsigned int. Feel free to submit a pull request that resolves this warning and I can help with reviewing. Thanks for working on the R package!

jwijffels commented 6 years ago

I'll see what I can do to fix these compiler warnings in a pull request.