This forum has been archived. All content is frozen. Please use KDE Discuss instead.

what is Eigen:: for MATLAB [val ind] = max(mat, [], 2)?

Tags: None
(comma "," separated)
floriano
Registered Member
Posts
2
Karma
0
Hi!
I'd like to do a rowwise max reduction as in the matlab command

Code: Select all
[val ind] = max(mat, [], 2)


I tried changing the eigen example on the website:
Code: Select all
#include <iostream>
#include <Eigen/Dense>

using namespace std;
using namespace Eigen;
int main()
{
    MatrixXf mat(2,4);
    mat << 1, 2, 6, 9,
           3, 1, 7, 2;
    MatrixXf::Index   maxIndex;
    VectorXf maxVal = mat.rowwise().maxCoeff(&maxIndex);
    std::cout << "Maxima at positions " << endl;
    std::cout << maxIndex << std::endl;
    std::cout << "maxVal " << maxVal << endl;
}

where my change was to alter from
Code: Select all
float maxNorm = mat.rowwise().sum().maxCoeff(&maxIndex);

to
Code: Select all
VectorXf maxVal = mat.rowwise().maxCoeff(&maxIndex);

this gives an error. is there any way to do this operation? i.e. take the max over each row and return maximal value and it's index?
thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Currently that's not possible. You can only do:

int i;
float x = mat.row(3).maxCoeff(&i);

or

VectorXf mat.rowwise().maxCoeff();

but not both. Feel free to add a feature request there: http://eigen.tuxfamily.org/bz and even try to propose a patch!! The relevant file is Eigen/src/Core/VectorwiseOp.h
floriano
Registered Member
Posts
2
Karma
0
thanks! i'll check it out.
jitseniesen
Registered Member
Posts
204
Karma
2
ggael wrote:Feel free to add a feature request there: http://eigen.tuxfamily.org/bz

There already is request for this feature there: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=401

A patch would still be very welcome!


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]