bab2min / tomotopy

Python package of Tomoto, the Topic Modeling Tool
https://bab2min.github.io/tomotopy
MIT License
548 stars 62 forks source link

C++17 compilation with Apple Clang #135

Closed ankane closed 2 years ago

ankane commented 2 years ago

Hi @bab2min, I've been trying to compile tomoto with C++17 for the Ruby library since the latest version of Rice - Ruby's version of pybind11 - no longer supports C++14.

To test it, I changed -std=c++1y to -std=c++17 in setup.py. It works great with GCC on Linux, but with Apple Clang on Mac, it errors with:

src/TopicModel/TopicModel.hpp:330:5: error: no matching function for call to 'to_keyz'
                                serializer::to_keyz(static_cast<const _Derived*>(this)->TMID),
                                ^~~~~~~~~~~~~~~~~~~
src/TopicModel/TopicModel.hpp:842:40: note: in instantiation of member function 'tomoto::TopicModel<Eigen::Rand::ParallelRandomEngineAdaptor<unsigned int, Eigen::Rand::MersenneTwister<__attribute__((__vector_size__(4 * sizeof(long long)))) long long, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>, 8>, 4, tomoto::ICTModel, tomoto::CTModel<tomoto::TermWeight::idf, Eigen::Rand::ParallelRandomEngineAdaptor<unsigned int, Eigen::Rand::MersenneTwister<__attribute__((__vector_size__(4 * sizeof(long long)))) long long, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>, 8>, 4>, tomoto::DocumentCTM<tomoto::TermWeight::idf>, tomoto::ModelStateCTM<tomoto::TermWeight::idf>>::_saveModel' requested here
                        static_cast<const _Derived*>(this)->_saveModel(writer, fullModel, extra_data);
                                                            ^
src/TopicModel/CTModel.hpp:244:3: note: in instantiation of member function 'tomoto::TopicModel<Eigen::Rand::ParallelRandomEngineAdaptor<unsigned int, Eigen::Rand::MersenneTwister<__attribute__((__vector_size__(4 * sizeof(long long)))) long long, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>, 8>, 4, tomoto::ICTModel, tomoto::CTModel<tomoto::TermWeight::idf, Eigen::Rand::ParallelRandomEngineAdaptor<unsigned int, Eigen::Rand::MersenneTwister<__attribute__((__vector_size__(4 * sizeof(long long)))) long long, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>, 8>, 4>, tomoto::DocumentCTM<tomoto::TermWeight::idf>, tomoto::ModelStateCTM<tomoto::TermWeight::idf>>::saveModel' requested here
                CTModel(const CTArgs& args)
                ^
src/TopicModel/CTModel.cpp:7:37: note: in instantiation of member function 'tomoto::CTModel<tomoto::TermWeight::idf, Eigen::Rand::ParallelRandomEngineAdaptor<unsigned int, Eigen::Rand::MersenneTwister<__attribute__((__vector_size__(4 * sizeof(long long)))) long long, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>, 8>, 4, tomoto::ICTModel, void, tomoto::DocumentCTM<tomoto::TermWeight::idf>, tomoto::ModelStateCTM<tomoto::TermWeight::idf>>::CTModel' requested here
                TMT_SWITCH_TW(_weight, scalarRng, CTModel, args);
                                                  ^
src/TopicModel/../Utils/serializer.hpp:165:21: note: candidate template ignored: could not match 'const char' against 'const char'
                constexpr Key<_n> to_keyz(const char(&a)[_n])
                                  ^

I haven't had any luck with my attempts to solve it, so was wondering if you had any ideas.

If not, no worries - thanks for taking the time to read.

bab2min commented 2 years ago

Hi @ankane Thank you for reporting potential compilation errors. I've patched the code to solve this issue. Please try with this branch (#139).

ankane commented 2 years ago

Big thanks @bab2min, works great! (in both Python and Ruby)