From: Miguel A. FigueroaVillanueva <miguelf@ie...>  20090329 14:07:37

On Sun, Mar 29, 2009 at 7:12 AM, Peter Vanroose wrote: > >> There is a min_value() function for vnl_matrix, but is there >> a way to get the location of that min value? >> An exhaustive search doesn't sound too nice on a 30,000 x 30,000 matrix! > > You'll have to run through all values anyhow to obtain the arg_min. > But it would indeed be nice to have a "builtin" method in vnl_matrix to do this; moreover, that method can then be optimized for speed, just like min_value() is. > > I'm currently putting in two functions arg_min() and arg_max() into all vector and matrix classes in vnl, next to min_value() and max_value(), which should do what you ask for. This just needs a little more of testing before I put it in the svn repository. > > There's of course no need for a combined min_value+arg_min function since, once you have the arg_min, it's straightforward (and optimal in terms of performance) to obtain the corresponding min_value from it. > > In case of ties, my implementation returns the smallest index with the min (or max) value. I believe this is the standard convention. > > I can post the svn diffs here (or mail them privately) if someone without access to the vxl repository wants to apply just this patch directly to his working copy of vxl. > >  Peter. Or you can open a ticket in trac and attach the patch there for posterity. Miguel 