Eigenを使用していますが、現在、行列の行を操作する関数を作成しようとしています。私はguidelines in the docsに従ってきましたが、コンパイルしようとするものは何もありません(clangまたはg ++のどちらでも)。私は知恵の終わりにいる。 RowXprを取る関数を実際にどのように書くべきでしょうか?参考のためRowXpr固有の関数
は、ここで私がこれまで試してみましたです:
#include <iostream>
#include <Eigen/Core>
using namespace std;
using namespace Eigen;
constexpr Eigen::StorageOptions Order = ColMajor;
using vect_t = Matrix<double, 1, 3, Order>;
using matr_t = Matrix<double, Dynamic, 3, Order>;
#define FUNC 3
#if FUNC == 1
vect_t func(const vect_t& f)
{
return f;
}
#elif FUNC == 2
vect_t func(const Ref<vect_t>& f)
{
return f;
}
#elif FUNC == 3
template<class D> vect_t func(const MatrixBase<D>& f)
{
return f;
}
#endif
int main()
{
matr_t M = matr_t::Random(5,3);
cout << M << endl;
cout << func(M.row(2)) << endl;
return 0;
}
ありがとう!
編集:打ち鳴らすと
(バージョン3.8.0-2ubuntu4)私が手にエラーが以下の通りです。このエラーはg ++に匹敵します。
[email protected]:~/workspace/scratch$ clang++ eigen_func_test.cpp -I /home/dan/Downloads/eigen_3.3.3/ --std=c++11 && ./a.out
In file included from eigen_func_test.cpp:2:
In file included from /home/dan/Downloads/eigen_3.3.3/Eigen/Core:436:
/home/dan/Downloads/eigen_3.3.3/Eigen/src/Core/PlainObjectBase.h:899:7: error: static_assert failed
"INVALID_MATRIX_TEMPLATE_PARAMETERS"
...EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dan/Downloads/eigen_3.3.3/Eigen/src/Core/util/StaticAssert.h:32:40: note: expanded from macro
'EIGEN_STATIC_ASSERT'
#define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
^ ~
/home/dan/Downloads/eigen_3.3.3/Eigen/src/Core/PlainObjectBase.h:535:7: note: in instantiation of member function
'Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 0, 1, 3> >::_check_template_params' requested here
_check_template_params();
^
/home/dan/Downloads/eigen_3.3.3/Eigen/src/Core/Matrix.h:379:9: note: in instantiation of function template
specialization 'Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 0, 1, 3>
>::PlainObjectBase<Eigen::Block<Eigen::Matrix<double, -1, 3, 0, -1, 3>, 1, 3, false> >' requested here
: Base(other.derived())
^
eigen_func_test.cpp:32:9: note: in instantiation of function template specialization 'Eigen::Matrix<double, 1, 3, 0,
1, 3>::Matrix<Eigen::Block<Eigen::Matrix<double, -1, 3, 0, -1, 3>, 1, 3, false> >' requested here
return f;
^
eigen_func_test.cpp:41:10: note: in instantiation of function template specialization
'func<Eigen::Block<Eigen::Matrix<double, -1, 3, 0, -1, 3>, 1, 3, false> >' requested here
cout << func(M.row(2)) << endl;
^
1 error generated.
どのようなコンパイルエラーが表示されますか?疑問に思えるのは、関数テンプレートが 'vect_t'の型を返すことを期待しており、' MatrixBase 'の' const ref'を返すということだけです。また、あなたの主な関数では、問題のもう一つの点は、あなたが 'matr_t'型である' M'を印刷しようとしているという事実かもしれません。 。 –
こんにちは@FrancisCugler、これはcoutとは関係ありませんが、この行は関数呼び出しをコメントアウトすると機能します。コンパイラ出力の例を追加しました。 – Dan
さて、私はそれがストリーム演算子から来ていないが、それはテンプレートパラメータ自体から来ていることがわかります。これはあなたの関数テンプレートから来ているようです。私はこのライブラリを知らないので、質問に答えるほどの答えを加えることはできませんが、私は、コンパイラがあなたのソースコードを使って何をしようとしているかについていくつかの洞察を与えることができます。 –