c++ Eigen:how to make code more elegant and faster when I must traverse each row of matrix

Viewed 76

When I write algorithm for point cloud in Eigen, I use Eigen::Matrix to represent point cloud. In many cases, I usually write code beblow

Eigen::Matrix Distance(const Eigen::MatrixXd& base,const Eigen::MatrixXd& center){
    Eigen::Matrix disRes;
    for(int i = 0;i < center.cols();++i){
        disRes.col(i) = (base.colwise() - center.col(i)).colwise().squaredNorm();
    }
    return std::move(disRes);
}

The code may be like this. How to make the code more elegant and faster when both input is more then 1e5 without parallel.

0 Answers
Related