首页 > 解决方案 > c++ eigen svd sum to float

问题描述

我正在计算矩阵的 bdcsvd ,然后像这样计算奇异值的总和

std::stringstream ss(mat_str);
int m = 66;
int n = 66;
MatrixXd A(m,n);
for(int i=0; i<m; ++i)
  for(int j=0; j<n; ++j)
    ss >> A(i,j);

Eigen::BDCSVD<MatrixXd> svd(A,ComputeFullU|ComputeFullV);
auto sum = svd.singularValues().colwise().sum().cast<float>();
cout << "Here is the type of :" << endl << typeid(sum).name() << endl;

sum 的类型显示N5Eigen12CwiseUnaryOpINS_8internal14scalar_cast_opIdfEEKNS_16PartialReduxExprIKNS_6MatrixIdLin1ELi1ELi0ELin1ELi1EEENS1_10member_sumIdEELi0EEEEE而不是 float 。我如何将总和转换/转换为浮点数?

标签: c++eigen

解决方案


推荐阅读