eigen/doc/examples/class_Cast.cpp
Gael Guennebaud 138aad0ed0 * coefficient wise operators are more generic, with controllable result type.
- compatible with current STL's functors as well as with the extention proposal (TR1)
 * thanks to the above, Cast and ScalarMultiple have been removed
 * benchmark_suite is more flexible (compiler and matrix size)
2008-03-06 11:36:27 +00:00

23 lines
610 B
C++

#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Scalar, typename Derived>
const Eigen::CwiseUnaryOp<
Eigen::ScalarCastOp<typename Eigen::NumTraits<Scalar>::FloatingPoint>,
Derived
>
castToFloatingPoint(const MatrixBase<Scalar, Derived>& m)
{
return m.template cast<typename Eigen::NumTraits<Scalar>::FloatingPoint>();
}
int main(int, char**)
{
Matrix2i m = Matrix2i::random();
cout << "Here's the matrix m. It has coefficients of type int."
<< endl << m << endl;
cout << "Here's m/20:" << endl << castToFloatingPoint(m)/20 << endl;
return 0;
}