2017-05-03 1 views
0

Eigenのthis pageの2番目の例を再現しようとしていますが、最小限のプログラムをコンパイルできません。私はEigen 3.3〜beta1-2を使用しています。CWigenNullaryOpでEigenを拡張:例を再現できません

次の引数-std=c++11 -Wall -pipe -O3 -ffast-math -funsafe-math-optimizations -march=native -mtune=native -pedantic -Wno-unused-variable -I/usr/local/include/eigen3 -I/usr/include/eigen3 -c example.cppとG ++を実行しているとき、私はこのエラーを取得:

example.cpp:8:41 ("Eigen::MatrixXi B = indexing(A, ri, ci)" in program below) 
/usr/include/eigen3/Eigen/src/Core/CoreEvaluators.h:348:27: error: no match for call to '(const indexing_functor<Eigen::Matrix<int, -1, -1>, Eigen::Array<int, 3, 1>, Eigen::Array<int, -1, 1> >) (Eigen::Index&) 
     return m_functor(index); 

私の最小限のプログラムは、(基本的にコピーして、ドキュメントの例から貼り付け)以下で構成されています

example.h

#include <iostream> 
#include <stdio.h> 
#include <Eigen/Core> 

using namespace Eigen; 

template<class ArgType, class RowIndexType, class ColIndexType> 
class indexing_functor { 
    const ArgType &m_arg; 
    const RowIndexType &m_rowIndices; 
    const ColIndexType &m_colIndices; 
public: 
    typedef Matrix<typename ArgType::Scalar, 
       RowIndexType::SizeAtCompileTime, 
       ColIndexType::SizeAtCompileTime, 
       ArgType::Flags&RowMajorBit?RowMajor:ColMajor, 
       RowIndexType::MaxSizeAtCompileTime, 
       ColIndexType::MaxSizeAtCompileTime> MatrixType; 
    indexing_functor(const ArgType& arg, const RowIndexType& row_indices, const ColIndexType& col_indices) 
    : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices) 
    {} 
    const typename ArgType::Scalar& operator() (Index row, Index col) const { 
    return m_arg(m_rowIndices[row], m_colIndices[col]); 
    } 
}; 

template <class ArgType, class RowIndexType, class ColIndexType> 
CwiseNullaryOp<indexing_functor<ArgType,RowIndexType,ColIndexType>, typename indexing_functor<ArgType,RowIndexType,ColIndexType>::MatrixType> 
indexing(const Eigen::MatrixBase<ArgType>& arg, const RowIndexType& row_indices, const ColIndexType& col_indices) 
{ 
    typedef indexing_functor<ArgType,RowIndexType,ColIndexType> Func; 
    typedef typename Func::MatrixType MatrixType; 
    return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices)); 
} 

例。

#include "example.h" 

int main() 
{ 
    Eigen::MatrixXi A = Eigen::MatrixXi::Random(4,4); 
    Array3i ri(1,2,1); 
    ArrayXi ci(6); ci << 3,2,1,0,0,2; 
    Eigen::MatrixXi B = indexing(A, ri, ci); 
    std::cout << "A =" << std::endl; 
    std::cout << A << std::endl << std::endl; 
    std::cout << "A([" << ri.transpose() << "], [" << ci.transpose() << "]) =" << std::endl; 
    std::cout << B << std::endl; 
} 

CPP私はテンプレートがC++でどのように機能するかについての基本的な何かが足りないのですか?

+0

これはおそらく問題ではないかもしれませんが、 '-I/usr/local/include/eigen3 -I/usr/include/eigen3'の両方を実行すべきではありません。これらの場所に互換性のないバージョンのEigenが存在する可能性があります – chtz

答えて

0

私は、Eigen 3.3〜beta1-2のUbuntu releaseに改変が必要であると判断したか、何らかの形でこの拡張機能のサポートが不足していると判断しました。このプログラムは、最新のヘッダーを使用するときに機能します。

関連する問題