<p>In <a href="https://github.com/mlpack/mlpack/pull/388#discussion_r23584017">src/mlpack/methods/mean_shift/mean_shift_impl.hpp</a>:</p>
<pre style='color:#555'>&gt; +      arma::Col&lt;double&gt; mhVector = newCentroid - allCentroids.col(i);
&gt; +      
&gt; +      // update the centroid.
&gt; +      allCentroids.col(i) = newCentroid;
&gt; +      
&gt; +      if (arma::norm(mhVector, 2) &lt; stopThresh ||
&gt; +          completedIterations &gt; maxIterations) {
&gt; +        break;
&gt; +      }
&gt; +      
&gt; +    }
&gt; +    
&gt; +  }
&gt; +  
&gt; +  // remove duplicate centroids.
&gt; +  for (size_t i = 0; i &lt; allCentroids.n_cols; ++i) {
</pre>
<p>Why not check if there is a duplicate centroid once you finish finding the centroid for an individual point?  If you refactor the code to only consider one centroid at a time and only add it to the results if it is not duplicated in the existing list of results, I think you will get faster (and more memory-efficient) code.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/pull/388/files#r23584017">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFIrSktV4B6ijTR1BFH4vCuAOATtPks5nlvQBgaJpZM4DTzb1.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/388/files#r23584017"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>