Substitutions for Eigen::MatrixXd typedefs

前端 未结 1 991
一生所求
一生所求 2021-01-25 18:37

What is the simplest way to replace all Eigen::MatrixXds and Eigen::VectorXds with Vectors and Matrices that have long double elements?

相关标签:
1条回答
  • 2021-01-25 19:06

    Simply define your own typedefs based on Eigen's own global matrix typedefs.

    If you use Eigen::MatrixXd and fill it with elements of type long double, those values will be narrowed to fit into the double elements of the matrix, which results in a loss of precision or, in the worst case, overflow errors. However, on many architectures double-precision floating point arithmetic is done in 80-bit extended precision, so the results may be the same. You surely shouldn't rely on this! For more see, e.g., long double vs double.

    #include <Eigen/Core>
    
    typedef Eigen::Matrix< long double, Eigen::Dynamic, 1              > Vec;
    typedef Eigen::Matrix< long double, Eigen::Dynamic, Eigen::Dynamic > Mat;
    
    int main()
    {
      long double ld = 2;
    
      Mat m(1,1);
      m(0,0) = ld;
    }
    
    0 讨论(0)
提交回复
热议问题