title: Is there a way to increase the performance of symmetric matrices using Armadillo in c++?
body: <p>I am using Armadillo for matrix calculations in c++, in order to calculate the distance between all particles in a x,y plane. i am using below class, in which <code>myParticls &amp;pSystem</code> is another class that holds information about all created particles.</p>
  
  <pre><code>    class DistMatrix
      {
          private:
              arma::Mat&lt;float&gt; _X;
              arma::Mat&lt;float&gt; _Y;
  
  
          public:
  
              DistMatrix(myParticls &amp;pSystem)
              {
               _X = arma::repmat(pSystem.x(), pSystem.size(), 1);
               _Y = arma::repmat(pSystem.y(), pSystem.size(), 1);
              }
  
              arma::Mat&lt;float&gt; DistanceMatrix()
              {
                  return arma::sqrt(arma::square(_X - _X.t()) + arma::square(_Y - _Y.t()));
  
              }
  
      };
  </code></pre>
  
  <p>the resulted matrix is a symmetric matrix, and by definition half of the operations i will apply to it will be wasted processing power and memory. my question is, is there a way to prevent duplicated operations to increase performance?</p>
  
  <p>i tried trimming the upper part of the matrix and changing its type to sparse matrix, but that only decreased the performance. i am new to c++, and programming in general.</p>