[eigen] maximum value for sparse vector

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,
I write a simple code to obtain the maximum coeff of a sparse vector (complex), is this efficient?  I notice there is
no  'maxCoeff' or 'minCoeff' function for sparse matrix.  Thanks!

typedef SparseVector< std::complex<double> > SpVecXcd;

double max_coeff(const SpVecXcd& m) {
  double max_val = std::numeric_limits<double>::min();
  double val;
  for (SpVecXcd::InnerIterator it(m); it; ++it) {
    val = sqrt(norm(it.value()));
    if (val > max_val)
      max_val = val;
  }
  return max_val;
}

Best regards,
Yan








Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/