title: Armadillo element-wise operations only on diagonal
body: <p>Does armadillo offer functions that apply element-wise operations only on the diagonal elements of a matrix? Say I want to run an inverse on it then I get infs on off-diagonals. I know that I can get it with <code>arma::inv(m)</code>, but for diagonal matrices it seems faster to run it element-wise.</p>
  <p>Minimal example:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;armadillo&gt;
  
  int main() {
    arma::Col&lt;double&gt; v = {1.2, 3.14, 2.71, 0.1};
    arma::Mat&lt;double&gt; m = arma::diagmat(v);
    std::cout &lt;&lt; &quot; A diagonal matrix:\n&quot; &lt;&lt; m &lt;&lt; &quot;\n\n&quot;;
    std::cout &lt;&lt; &quot; It's elemenet-wise inverse:\n&quot; &lt;&lt; 1.0/m &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>