0
点赞
收藏
分享

微信扫一扫

Eigen库常用功能(好用点赞)

祈澈菇凉 2022-02-11 阅读 38
c++

1、判断两个矩阵是否相等(对应元素之差的绝对值小于一个很小的浮点数)

template<typename Derived>
bool judgeEigenMatrixEqual(const Eigen::MatrixBase<Derived>& mat1, const Eigen::MatrixBase<Derived>& mat2, const double precision = 1e-5)
{
	if (mat1.rows() != mat2.rows() || mat1.cols() != mat2.cols()) return false;
	return ((mat1.array() - mat2.array()).cwiseAbs().cast<double>().maxCoeff() < precision);
}

//使用
Eigen::MatrixXf mat1, mat2;
bool isEqual = judgeEigenMatrixEqual<Eigen::MatrixXf>(mat1, mat2);
	

2、Eigen::vector与std::vector的相互转换,std::vector转Eigen::MatrixXd也类似

(参考https://blog.csdn.net/github_39582118/article/details/120309991)

举报

相关推荐

0 条评论