Submatrices and indices using Eigen

前端 未结 4 1454
[愿得一人]
[愿得一人] 2021-02-04 06:46

I\'m currently working on a MATLAB project and I\'d like to re-implement the most computational-heavy parts using C++ and Eigen. I\'d like to know if there\'s a way to perform t

相关标签:
4条回答
  • 2021-02-04 07:00

    The latest development available on master branch of Eigen allows to work with numerical indices.

    Here is a similar request, that shows an example of numerical indexing

    0 讨论(0)
  • 2021-02-04 07:02

    You can perform operations on selected elements only with select(), which is the equivalent for the ternary ?: operator. This is not exactly what you wanted, but should work in many cases.

    MatrixXd B = (A.array() < 3).select(operation_on(A), MatrixXd::Zero(A.rows(), A.cols()));
    

    This will fill B with zeros if A<3 and the result of any required operation on A otherwise.

    0 讨论(0)
  • 2021-02-04 07:18

    There currently is a feature request for selecting sub-matrices by indexing filed at the Eigen BugTracker system. Therefore, I doubt it will be possible that way.

    The only workaround I could think of is to copy the data manually. Not very nice though.

    0 讨论(0)
  • 2021-02-04 07:23

    libigl has many wrappers for Eigen to make it feel more like MATLAB. In particular, there is a slice function so that you can call:

    igl::slice(A,indices,B);
    

    which is equivalent to MATLAB's

    B = A(indices)
    
    0 讨论(0)
提交回复
热议问题