title: Element-wise max and positive part in Eigen
body: <p>I would like to take the element-wise max of two vectors/matrices in Eigen. So far, I've written this code:</p>
  
  <pre><code>template &lt;typename S, typename T&gt;
  auto elemwise_max(const S &amp; A, const T &amp; B) {
      return (A.array() &gt; B.array()).select(A, B); 
  }
  </code></pre>
  
  <p>Is this correct, or is this there a better way of doing this?</p>
  
  <p>For the positive part (ie. <code>max(A, 0)</code>), I'm not sure how to proceed. Do I need to create two methods?</p>
  
  <pre><code>template &lt;typename S&gt;
  auto positive_part_matrix(const S &amp; A) {
     auto zeros = S::Zero(A.rows(), A.cols());
     return elemwise_max(A, zeros);
  }
  
  template &lt;typename S&gt;
  auto positive_part_vec(const S &amp; A) {
     auto zeros = S::Zero(A.size());
     return elemwise_max(A, zeros);
  }
  </code></pre>
  
  <p>Ideally both of the above would just be called <code>positive_part</code>.</p>