title: Implementation of ReLU function on C++
body: <p>I'm actually working on a CNN, I'm using a Sigmoid for the activation function, but i would like to use the ReLU.</p>
  
  <p>I have implemented a code for ReLU using Eigen, but it doesn't seems to work, can you help me please ? </p>
  
  <p>Here's my code:</p>
  
  <pre><code>Matrix ReLu(const Matrix &amp; x){
  
      Matrix A;
      for( int i = 0; i&lt; x.rows(); ++i )
      for (int j=0; i&lt; x.cols(); j++) {
          if (x(i,j) &lt;= 0){
              A(i,j)=(0.0);
          }
          else A(i,j)=(x(i,j));
      }
      return std::move(A.matrix());
  }
  
  Matrix ReLu_deriv (const Matrix&amp; y) {
      Matrix B;
      for( int i = 0; i &lt; y.rows(); ++i )
      for (int j=0; i &lt; y.cols() ; j++)
      {
          {
          if (y(i,j) &lt;= 0.0){
              B(i,j)=(0.0);
          }
          else B(i,j)=(1.0);
      }
      return std::move(B.matrix());
  }
  </code></pre>
  
  <p>and the error is : </p>
  
  <pre><code>&gt; /usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h :365 : Eigen::DenseCoeffsBase&lt;Derived,
  &gt; 1&gt;::Scalar&amp; Eigen::DenseCoeffsBase&lt;Derived,
  &gt; 1&gt;::operator()(Eigen::Index, Eigen::Index) [with Derived =
  &gt; Eigen::Matrix&lt;double, -1, -1&gt;; Eigen::DenseCoeffsBase&lt;Derived,
  &gt; 1&gt;::Scalar = double; Eigen::Index = long int]:  l'assertion « row &gt;= 0
  &gt; &amp;&amp; row &lt; rows() &amp;&amp; col &gt;= 0 &amp;&amp; col &lt; cols() » a échoué.
  </code></pre>