forked from parallella/pal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_max.c
31 lines (27 loc) · 735 Bytes
/
p_max.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <pal.h>
/**
*
* Finds the maximum value in vector 'a'. Returns the index of the max
*
* @param a Pointer to input vector
*
* @param c Pointer to output scalar
*
* @param[out] index Pointer to return index of max (note that if there are multiple cells with max, the first index will be returned)
*
* @param n Size of 'a' vector.
*
* @return None
*
*/
void PSYM(p_max)(const PTYPE *a, PTYPE *c, int *index, int n)
{
if (n==0) return; // only do work if there are elements
int pos = 0;
for (int i = 1; i < n; i++) {
int greater = (*(a + i) > *(a + pos));
pos = greater * i + (1 - greater) * pos;
}
*c = *(a + pos);
*index = pos;
}