title: Eigen c++ casting
body: <p>I'm having trouble multiplying two matrices using the Eigen library. I have the following function. Here is a small example of what I would like to do :</p>
  
  <p>Program name: testMatOp.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Eigen/Dense&gt;
  using namespace std;
  
  template &lt;typename DerivedA, typename DerivedB&gt;
  void multiply(const Eigen::MatrixBase&lt;DerivedA&gt; &amp;A,
                 const Eigen::ArrayBase&lt;DerivedB&gt; &amp;B){
    Eigen::MatrixXf C(2,4);
    C.array() = A.array().rowwise() * B.cast&lt;float&gt;();
  }
  
  int main()
  {
    Eigen::MatrixXf A(2,4);
    Eigen::MatrixXf C(2,4);
    //igen::VectorXf v(4);
    Eigen::Array&lt;int,1,Eigen::Dynamic&gt;B;
    B.resize(4);
  
    A &lt;&lt; 1, 2, 6, 9,
           3, 1, 7, 2;
  
    B &lt;&lt; 0,
         1,
         0,
         0;
  
    multiply(A,B);
  }
  </code></pre>
  
  <p>I would like to pass Matrix A and Vector B to multiply. I understand that Eigen does not do automatic promotion and that B needs to be casted as a float vector in order for the multiplication to happen. When I compile, I get the following compilation error among others</p>
  
  <pre><code>testMatOp.cpp:34:44: error: expected primary-expression before 'float'
  testMatOp.cpp:34:44: error: expected ';' before 'float'
  testMatOp.cpp: In instantiation of 'void multiply(const Eigen::MatrixBase&lt;Derived&gt;&amp;, const Eigen::ArrayBase&lt;DerivedB&gt;&amp;) [with DerivedA = Eigen::Matrix&lt;float, -1, -1&gt;; DerivedB = Eigen::Array&lt;int, 1, -1&gt;]':
  testMatOp.cpp:54:15:   required from here
  testMatOp.cpp:34:3: error: no match for 'operator*' in '((const Eigen::DenseBase&lt;Eigen::ArrayWrapper&lt;const Eigen::Matrix&lt;float, -1, -1&gt; &gt; &gt;*)(&amp;(&amp; A)-&gt;Eigen::MatrixBase&lt;Derived&gt;::array&lt;Eigen::Matrix&lt;float, -1, -1&gt; &gt;()))-&gt;Eigen::DenseBase&lt;Derived&gt;::rowwise&lt;Eigen::ArrayWrapper&lt;const Eigen::Matrix&lt;float, -1, -1&gt; &gt; &gt;() * B.Eigen::ArrayBase&lt;Derived&gt;::cast&lt;NewType&gt;'
  testMatOp.cpp:34:3: note: candidates are:
  In file included from ../3rdparty/Eigen/Core:336:0,
                   from ../3rdparty/Eigen/Dense:1,
                   from testMatOp.cpp:26:
  </code></pre>
  
  <p>What might I be doing wrong. I did take a look at this post :
  <a href="https://stackoverflow.com/questions/24764031/cast-eigenmatrixxd-to-eigenmatrixxf">Cast Eigen::MatrixXd to Eigen::MatrixXf</a> 
  which correctly describes how to cast, but I'm unable to make it work for this example. </p>
  
  <p>Any help would be appreciated. Thanks!</p>
  
  <p>-a</p>