2016-08-04 11 views
1

を高速化RNNLMをコンパイルするには、私は、Visual Studioでの高速化RNNLMをコンパイルしようとしています2012年 https://github.com/yandex/faster-rnnlm問題のWindows

は問題は(それは私がVSでコンパイルすることはできませんよ固有のライブラリーからいくつかのテンプレート機能を使用していることですLinux/Cygwinで完全にコンパイルされています)。具体的には、機能は次のとおりです。

typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> RowMatrix; 
typedef Eigen::Matrix<Real, 1, Eigen::Dynamic, Eigen::RowMajor> RowVector; 

template<int rows> 
inline void Dump(const Eigen::Matrix<Real, rows, Eigen::Dynamic, Eigen::RowMajor>& matrix, FILE* fo) { 
    fwrite(matrix.data(), sizeof(Real), matrix.rows() * matrix.cols(), fo); 
} 


template<int rows> 
inline void Load(Eigen::Matrix<Real, rows, Eigen::Dynamic, Eigen::RowMajor>* matrix, FILE* fo) { 
    FreadAllOrDie(
     matrix->data(), sizeof(Real), matrix->rows() * matrix->cols(), fo, 
     "failed to read matrix"); 
} 

template<class Matrix> 
void DumpMatrixArray(std::vector<Matrix*> array, FILE* fo) { 
    for (size_t i = 0; i < array.size(); ++i) { 
    Dump(*array[i], fo); 
    } 
} 


template<class Matrix> 
void LoadMatrixArray(std::vector<Matrix*> array, FILE* fo) { 
    for (size_t i = 0; i < array.size(); ++i) { 
     Load(array[i], fo); 
    } 
} 

私はコンパイル時に取得していますエラーは次のとおりです。

Error 112 error C2784: 'void Dump(const Eigen::Matrix<Real,rows,-1,1> &,FILE *)' : could not deduce template argument for 'const Eigen::Matrix<Real,rows,-1,1> &' from 'RowMatrix'  
Error 35 error C2784: 'void Dump(const Eigen::Matrix<Real,rows,-1,1> &,FILE *)' : could not deduce template argument for 'const Eigen::Matrix<Real,rows,-1,1> &' from 'const RowMatrix' 
Error 115 error C2784: 'void Load(Eigen::Matrix<Real,rows,-1,1> *,FILE *)' : could not deduce template argument for 'Eigen::Matrix<Real,rows,-1,1> *' from 'Eigen::Matrix<_Scalar,_Rows,_Cols> *' 
Error 19 error C2784: 'void Load(Eigen::Matrix<Real,rows,-1,1> *,FILE *)' : could not deduce template argument for 'Eigen::Matrix<Real,rows,-1,1> *' from 'Eigen::Matrix<_Scalar,_Rows,_Cols,_Options> *' 

私は小さなコードを作成した詳細に問題をtounderstand。 Dump<5>(rm, temp)のような行数のダンプを呼び出すと、このコードは完全にコンパイルされます。しかし、コンパイル時に行数がわからないので、実際のコードでは使用できません。私が持っている サンプルコードは次のとおりです。コードはコンパイルとVS2012でのLinux/Cygwinの中で働いていないが、なぜ

#include <iostream> 
#include <Eigen/Dense> 

typedef float Real; 
typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> RowMatrix; 
typedef Eigen::Matrix<Real, 1, Eigen::Dynamic, Eigen::RowMajor> RowVector; 
template<int rows> 
inline void Dump(const Eigen::Matrix<Real, rows, Eigen::Dynamic, Eigen::RowMajor>& matrix, FILE* fo) { 
    fwrite(matrix.data(), sizeof(Real), matrix.rows() * matrix.cols(), fo); 
} 


template<int rows> 
inline void Load(Eigen::Matrix<Real, rows, Eigen::Dynamic, Eigen::RowMajor>* matrix, FILE* fo) { 
    FreadAllOrDie(
     matrix->data(), sizeof(Real), matrix->rows() * matrix->cols(), fo, 
     "failed to read matrix"); 
} 

inline void FreadAllOrDie(void* ptr, size_t size, size_t count, FILE* fo, const char* message) { 
    size_t read = fread(ptr, size, count, fo); 
    if (read != count) { 
    fprintf(
     stderr, "ERROR: expected to read %zu elements, but read %zu elements (%s)\n", 
     count, read, message); 
    exit(1); 
    } 
} 

using namespace std; 
using namespace Eigen; 
int main() 
{ 
    RowMatrix rm; 
    FILE* temp = fopen("temp", "wb"); 
    rm.resize(5,5); 
    Dump(rm, temp); 
    MatrixXd m = MatrixXd::Random(3,3); 
    m = (m + MatrixXd::Constant(3,3,1.2)) * 50; 
    cout << "m =" << endl << m << endl; 
    VectorXd v(3); 
    v << 1, 2, 3; 
    cout << "m * v =" << endl << m * v << endl; 
    getchar(); 
} 

は、誰かが私が間違っているのを教えすることができます。

答えて

1

コンパイル時に不明な行の数がテンプレート引数として使用できません。

Dump<5>(rm, temp); 

int five = 5; 
Dump<five>(rm, temp); 

はしませんのようなコールに対し動作します:テンプレートはそのような呼び出しは、コンパイル時にインスタンス化されています。 Eigenに関しては、コンパイル時の行数が分からない場合、行数はEigen::Dynamicまたは-1と表されます。コンパイラはRowMatrixEigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>のtypedefであるため、これを推論することができます。そうでない場合は、

Dump<rm.RowsAtCompileTime>(rm, temp); 
+0

を使用して問題を強制することができますが、問題はCygwinで問題なくコンパイルされていることです。 VSでのみエラーが発生します。だから私はそれが私が把握することができないVSと何かをしなければならないと仮定する。 – funkyme

+0

私が言及したように、コンパイラ(cl.exe)は何らかの理由で、情報が 'rm'の中で提供されていてもテンプレート引数を正確に推測しません。これはVisual Studioの欠点の1つに過ぎません。 「なぜVSが正しくテンプレート引数を推論しないのですか」という質問には多くの質問があります。答えは基本的に「コンパイラのバグ」です。 –

関連する問題