title: Eigen Library: why is my function copying my argument when it shouldn't?
body: <p>In my case, the MatrixXd object "AA" is a large matrix and absolutely cannot be copied. It seems that the below function should not copy it, but in fact it does copy it. I'm by no means a programming and surely I'm doing something horribly wrong, but I cannot figure out just what it is</p>
  
  <pre><code>void GKLBidiag(const Ref&lt;const MatrixXd&gt;&amp; AA, double&amp; eigenv, Ref&lt;VectorXd&gt; v,     Ref&lt;VectorXd&gt; alpha, Ref&lt;VectorXd&gt; beta) {
  
    VectorXd u(AA.rows());
    VectorXd Uprev(v.size());
    VectorXd Vnew(v.size());
    const int kmax(alpha.size());
    MatrixXd B(MatrixXd::Zero(kmax, kmax));
  
  
    v.normalize();
  
    for (int i = 0; i &lt; kmax; i++) {
      Uprev = u;
      u = AA * v;
      if (i &gt; 0) {
        u -= beta(i - 1) * Uprev;
        //add reorthogonalization
      }
      alpha(i) = u.norm();
      u /= alpha(i);
      Vnew = AA.adjoint() * u - alpha(i) * v;
      beta(i) = Vnew.norm();
      v = Vnew.array() / beta(i);
    }
  
    B.diagonal() = alpha;
    for (int i = 0; i &lt; kmax - 1; i++) {
      B(i, i + 1) = beta(i);
    }
  
    JacobiSVD&lt;MatrixXd&gt; svd(B);
    eigenv = pow(svd.singularValues()(0), 2);
  
  }
  </code></pre>
  
  <p>Help would be greatly appreciated!</p>