| 1 |
/* |
| 2 |
* Copyright 1997, Regents of the University of Minnesota |
| 3 |
* |
| 4 |
* util.c |
| 5 |
* |
| 6 |
* This function contains various utility routines |
| 7 |
* |
| 8 |
* Started 9/28/95 |
| 9 |
* George |
| 10 |
* |
| 11 |
* $Id: util.c 10495 2011-07-06 16:04:45Z karypis $ |
| 12 |
*/ |
| 13 |
|
| 14 |
#include "metislib.h" |
| 15 |
|
| 16 |
/*************************************************************************/ |
| 17 |
/*! Returns the highest weight index of x[i]*y[i] |
| 18 |
*/ |
| 19 |
/*************************************************************************/ |
| 20 |
idx_t iargmax_nrm(size_t n, idx_t *x, real_t *y) |
| 21 |
{ |
| 22 |
idx_t i, max=0; |
| 23 |
|
| 24 |
for (i=1; i<n; i++) |
| 25 |
max = (x[i]*y[i] > x[max]*y[max] ? i : max); |
| 26 |
|
| 27 |
return max; |
| 28 |
} |
| 29 |
|
| 30 |
/*************************************************************************/ |
| 31 |
/*! These functions return the index of the second largest elements in the |
| 32 |
vector formed by x.y where '.' is element-wise multiplication */ |
| 33 |
/*************************************************************************/ |
| 34 |
idx_t iargmax2_nrm(size_t n, idx_t *x, real_t *y) |
| 35 |
{ |
| 36 |
size_t i, max1, max2; |
| 37 |
|
| 38 |
if (x[0]*y[0] > x[1]*y[1]) { |
| 39 |
max1 = 0; |
| 40 |
max2 = 1; |
| 41 |
} |
| 42 |
else { |
| 43 |
max1 = 1; |
| 44 |
max2 = 0; |
| 45 |
} |
| 46 |
|
| 47 |
for (i=2; i<n; i++) { |
| 48 |
if (x[i]*y[i] > x[max1]*y[max1]) { |
| 49 |
max2 = max1; |
| 50 |
max1 = i; |
| 51 |
} |
| 52 |
else if (x[i]*y[i] > x[max2]*y[max2]) |
| 53 |
max2 = i; |
| 54 |
} |
| 55 |
|
| 56 |
return max2; |
| 57 |
} |
| 58 |
|
| 59 |
|