New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 401 - obtain the coefficients of the indices for a row/colwise call to maxCoeff
Summary: obtain the coefficients of the indices for a row/colwise call to maxCoeff
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.4 (development)
Hardware: All All
: Normal Feature Request
Assignee: Nobody
Depends on: 984
  Show dependency treegraph
Reported: 2012-01-05 22:49 UTC by abachrach
Modified: 2016-02-23 22:36 UTC (History)
5 users (show)


Description abachrach 2012-01-05 22:49:47 UTC
Reminder for implementing the features requested in this thread:

Basically, it would be nice to be able to get the indices of the min/max in each row in addition to the value


  ArrayXXd test= ArrayXXd::Random(5,5);
  ArrayXi inds;
  ArrayXd mtest = test.rowwise().maxCoeff(inds);
Comment 1 abachrach 2012-01-11 15:08:55 UTC
Just looked into attempting this, and unfortunately think it's well above my pay grade (for now :-p)

As far as I can tell, it'll require fairly major changes to the VectorWiseOp class because it currently only allows Unary Expressions. I could be (probably am) wrong though...
Comment 2 Christoph Hertzberg 2013-11-18 14:52:47 UTC
I'm afraid this is a bit complicated, due to lazy evaluation. At the moment
does nothing until it is assigned to a variable or individual coefficients are evaluated. That would be very non-intuitive for the requested variant.
Maybe an alternative would be to essentially return a pair of two arrays (essentially, this is what Matlab does) -- I don't know how well this can be implemented with lazy evaluation, though.
A simpler solution would be to simply implement a maxCoeffIdx() which only returns an index vector. Or maybe it's possible to disable lazy evaluation for this expression?
Comment 3 Rasmus Munk Larsen 2016-02-23 21:43:15 UTC

Christoph, I think having something like the maxCoeffIdx() you suggest (and perhaps a companion maxCoeffVal()) would be very helpful.
Comment 4 Christoph Hertzberg 2016-02-23 22:36:58 UTC
Another idea would be implementing the technique suggested in Bug 984, i.e. something like
  vals, idxs = test.rowwise().maxCoeff();
  (vals, idxs) = test.rowwise().maxCoeff();

Note You need to log in before you can comment on or make changes to this bug.