<p>In <a href="https://github.com/mlpack/mlpack/pull/391#discussion_r23537713">src/mlpack/core/math/lin_alg.cpp</a>:</p>
<pre style='color:#555'>&gt; +      else
&gt; +        output(idx++) = M_SQRT2 * input(i, j);
&gt; +    }
&gt; +  }
&gt; +}
&gt; +
&gt; +void mlpack::math::Svec(const arma::sp_mat&amp; input, arma::sp_vec&amp; output)
&gt; +{
&gt; +  const size_t n = input.n_rows;
&gt; +  const size_t n2bar = n * (n + 1) / 2;
&gt; +
&gt; +  output.zeros(n2bar, 1);
&gt; +
&gt; +  size_t idx = 0;
&gt; +
&gt; +  for (auto it = input.begin(); it != input.end(); ++it)
</pre>
<p>If you use <code>row_col_iterator</code> (which, of course, isn't documented on the website... I'll have to make a change and submit it...), which exists for both <code>mat</code> and <code>sp_mat</code>, it will iterate over all points in <code>mat</code> and all nonzero points in <code>sp_mat</code>.  Using that, you could condense <code>Svec</code> into one templated function, and the speed should be equal to either implementation here.</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/391/files#r23537713">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFN8Pulo-pvTbqWHPROukjItDzyl0ks5nllVHgaJpZM4DVljE.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/391/files#r23537713"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>