title: Using templates to allow usage of arbitrary LinAlg libraries
body: <p>I have a function that performs some linear algebra calculations, for which I currently use <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page" rel="nofollow noreferrer">the Eigen library</a>.</p>
  
  <p>The function looks like that:</p>
  
  <pre><code>void Predict(const MatrixXd&amp; F,
          VectorXd&amp; x,
          VectorXd&amp; u,
          MatrixXd&amp; P,
          MatrixXd&amp; Q)
      {
          x = F*x + u;
          P = F*P*F.transpose() + Q;
      }
  </code></pre>
  
  <p>Now I want to generalize this function using templates, such that a client can use an arbitrary LinAlg library. My first approach looks like this:</p>
  
  <pre><code>template&lt;typename Matrix, typename Vector&gt;
      void Predict(const Matrix&amp; F,
          Vector&amp; x,
          Vector&amp; u,
          Matrix&amp; P,
          Matrix&amp; Q)
      {
          x = F*x + u;
          P = F*P*F.transpose() + Q;
      }
  </code></pre>
  
  <p>The obvious problem however is, that the function depends on a <code>transpose()</code> method. Although the underlying functionality should be implemented by any LinAlg - implementation, the signatures of the according methods can and very like will vary. One solution would be to pass the transposed Matrix as a parameter, which would work in this case, but not in cases where this can't be calculated beforehand. So whats the best way to abstract away constraints like this? </p>