Note that there are some explanatory texts on larger screens.

plurals
  1. POEigen: m(:, v > 0) and m(:, [1,3])
    primarykey
    data
    text
    <p>I'm trying to implement Matlab's m(:, v > 0) and m(:,[1,3]) in Eigen. So far I got the following functions:</p> <pre><code>MatrixXd select_cols(const MatrixXd src, const Matrix&lt;bool, 1, Dynamic&gt; cond) { MatrixXd dst(src.rows(), cond.count()); unsigned int i = 0; for (unsigned int j = 0; j &lt; cond.cols(); j++) { if (cond(0,j)) { dst.col(i++) = src.col(j); } } return dst; } MatrixXd select_cols(const MatrixXd src, const Matrix&lt;unsigned int, 1, Dynamic&gt; idx) { MatrixXd dst(src.rows(), idx.size()); for (unsigned int i = 0; i &lt; idx.size(); ++i) { dst.col(i) = src.col(idx[i]); } return dst; } </code></pre> <p>However, I thought that the following snippet will work, but it does't:</p> <pre><code>Eigen::MatrixXd m1(3,3); Eigen::Matrix&lt;unsigned int, 1, Eigen::Dynamic&gt; v(3); m1 &lt;&lt; 1,2,3, 4,5,6, 7,8,9; v &lt;&lt; 2,0,2; Eigen::MatrixXd m2 = Eigen::select_cols(m1, v.array() &gt; 1); </code></pre> <p>There is the error: </p> <pre><code>utest.cpp:88:62: error: call of overloaded ‘select_cols(Eigen::MatrixXd&amp;, const Eigen::CwiseUnaryOp&lt;std::binder2nd&lt;std::greater&lt;unsigned int&gt; &gt;, const Eigen::ArrayWrapper&lt;Eigen::Matrix&lt;unsigned int, 1, -0x00000000000000001&gt; &gt; &gt;)’ is ambiguous utest.cpp:88:62: note: candidates are: common.h:29:14: note: Eigen::MatrixXd Eigen::select_cols(Eigen::MatrixXd, Eigen::Matrix&lt;unsigned int, 1, -0x00000000000000001&gt;) common.h:32:14: note: Eigen::MatrixXd Eigen::select_cols(Eigen::MatrixXd, Eigen::Matrix&lt;bool, 1, -0x00000000000000001&gt;) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload