title: Efficiently perform a signed square root on a L1 normalized OpenCV descriptor
body: <p>I have matrix where each row is a SURF descriptor in 64 dimensions. For each row, I need to:</p>
  
  <ol>
  <li>L1 normalize it</li>
  <li>For each element, compute its signed square root</li>
  </ol>
  
  <p>The only way that I came out with this is:</p>
  
  <pre><code>template &lt;typename T&gt; int sgn(T val) {
      return (T(0) &lt; val) - (val &lt; T(0));
  }
  
  void SURFOpenCV::ComputeDescriptors(cv::Mat &amp;img, cv::Mat1f &amp;descriptors){
      descriptors.release();
      std::vector&lt;cv::KeyPoint&gt; pts;
      surf-&gt;detectAndCompute(img, cv::Mat(), pts, descriptors);
      //if there is at least one keypoint
      if(pts.size()){
          // For each row
          for (int i = 0; i &lt; descriptors.rows; ++i) {
              // Perform L1 normalization on the whole descriptor
              cv::normalize(descriptors.row(i), descriptors.row(i), 1.0, 0.0, cv::NORM_L1);
              for (int j = 0; j&lt;descriptors.cols; j++) {
                  float val = descriptors.at&lt;float&gt;(i,j);
                  descriptors.at&lt;float&gt;(i,j) = sgn(val) * std::sqrt(val);
              }
          }
      }
  }
  </code></pre>
  
  <p>But since <strong>performance are crucial</strong>, this looks kinda inefficient to me. Any better (faster) solution?</p>