C ++ Eigen :: Matrix-Typen über Templates ausgeben
Ich schreibe eine C ++ - Funktion, die als Typvorlage dient (entwederfloat
oderdouble
) und benutztEigen::Matrix
im Inneren. Die Funktion verwendet eine Kombination vonfloat
, double
und Template-TypEigen:Matrix
Objekte.Eigen::Matrix<>::cast()
funktioniert gut fürdouble
undfloat
, obwohl ich auf ein seltsames Problem stoße, wenn ich es mit Vorlagen-Typen verwende. Siehe Code unten:
#include "Eigen/Core" // Version 3.2.4 (eigen-eigen-10219c95fe65)
template <typename Scalar>
void Foo() {
Eigen::Matrix<double, 3, 1> mat_d = Eigen::Matrix<double, 3, 1>::Zero();
Eigen::Matrix<float, 3, 1> mat_f = Eigen::Matrix<float, 3, 1>::Zero();
Eigen::Matrix<Scalar, 3, 1> mat_s = Eigen::Matrix<Scalar, 3, 1>::Zero();
mat_d = mat_f.cast<double>(); // Works
mat_f = mat_f.cast<float>(); // Works
mat_s = mat_f.cast<Scalar>(); // Works
mat_s = mat_d.cast<Scalar>(); // Works
mat_d = mat_s.cast<double>(); // Broken
mat_f = mat_s.cast<float>(); // Broken
}
int main() {
Foo<double>();
Foo<float>();
}
Hier ist das Ergebnis der Kompilierung:
> g++ casting.cpp
casting.cpp: In function ‘void Foo()’:
casting.cpp:16:22: error: expected primary-expression before ‘double’
mat_d = mat_s.cast<double>(); // Broken
^
casting.cpp:16:22: error: expected ‘;’ before ‘double’
casting.cpp:17:22: error: expected primary-expression before ‘float’
mat_f = mat_s.cast<float>(); // Broken
^
casting.cpp:17:22: error: expected ‘;’ before ‘float’
Seit ich die Vorlage immer nur mit @ instanziieScalar
Als eindouble
oderfloat
, Ich würde mir vorstellen, dass dieScalar
Funktionsaufrufe sollten den gleichen Effekt haben wie die fest codiertenfloat
/double
types.
Ein paar weitere Systeminformationen:
Ubuntu 14.04 g ++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2Eigen 3.2.4, heruntergeladen vonhttp: //eigen.tuxfamily.orgVielen Dank im Voraus für Ihre Hilfe