Eigen :: Refを使用して、Eigen :: Matrix引数を使用してテンプレート以外の関数を使用したいとします。私の問題は、これらの関数では、Eigen :: Refによって参照される行列のサイズを変更する必要があるかもしれないということです。一般的にEigen :: Refは式や行列ブロックにマップできるのでサイズを変更してはいけませんが、私の場合はEigen :: Refの背後にあるものがEigen :: Matrixであると確信しています。この説明するためにEigen :: Refのサイズ変更の回避策
:
#include "Eigen/Dense"
void add(Eigen::Ref<Eigen::MatrixXd> M, const Eigen::Ref<const Eigen::MatrixXd> &A, const Eigen::Ref<const Eigen::MatrixXd> &B) {
M=A+B;
}
int main() {
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 32, 32> M(2,3);
Eigen::Matrix<double, 2, 2> A;
Eigen::Matrix<double, 2, 2> B;
add(M,A,B);
}
は、実行時に提供します:
void add(Eigen::Ref<Eigen::MatrixXd> M, const Eigen::Ref<const Eigen::MatrixXd> &A, const Eigen::Ref<const Eigen::MatrixXd> &B) {
Eigen::Ref<Eigen::Matrix<double,2,2>> MM(M);
MM=A+B;
}
が、私は、実行時に得た:
void Eigen::DenseBase<Derived>::resize(Eigen::Index, Eigen::Index) [with Derived = Eigen::Ref<Eigen::Matrix<double, -1, -1> >; Eigen::Index = long int]: Assertion `rows == this->rows() && cols == this->cols() && "DenseBase::resize() does not actually allow to resize."' failed.
私はそれをカンニングしようとした
Eigen::internal::variable_if_dynamic<T, Value>::variable_if_dynamic(T) [with T = long int; int Value = 2]: Assertion `v == T(Value)' failed.
これを処理するにはどうすればよいですか? Eigenのドキュメントでは、サイズ変更の問題は引数としてMatrixBaseを使用するテンプレート関数に対して扱いますが、Eigen :: Ref?ここで
:: MatrixXd& M? – chtz
申し訳ありませんが、あなたの質問を完全に読んだことはありません。 '32'が常に同じではないと仮定すると、テンプレートパラメータとして渡すことができます。さもなければ、私はこれを実装する安全な方法を見ません。 – chtz
私はそれを仮想化したいので、私はテンプレート関数を望んでいません。 – janou195