title: Checking if all entries in the matrix are zero in Eigen Library
body: <p>First of all, I'm not really sure if this is possible. I would like to check whether a matrix is zero or not in Eigen Library (note: I have to declare it). My solution is to check if all elements are zero. My question is Is there another way fulfill this task while keeping the size of the matrix unchanged?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Eigen/Dense&gt;
  
  // true if it is empty, false if not
  bool isEmpty(Eigen::MatrixXd&amp; Z)
  {
     bool check = true;
  
     for (int row(0); row &lt; Z.rows(); ++row)
      for (int col(0); col &lt; Z.cols(); ++col){
          if ( Z(row,col) != 0 ){
              check = false;
              break;
          }
       }
  
     return check;
  }
  
  
  int main()
  {
      Eigen::MatrixXd Z(3,3);
  
      if ( isEmpty(Z) )
          std::cout &lt;&lt; Z.size() &lt;&lt; std::endl;
      else
          Z.setZero(0,0); // resize the matrix (not clever way I know)
  
      std::cin.get();
      return 0;
  }
  </code></pre>