comparison toolboxes/distance_learning/mlr/util/cummax.c @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 /* CREATED:2010-01-08 17:25:37 by Brian McFee <bmcfee@cs.ucsd.edu> */
2 /* cummax.c
3 *
4 * cumulative maximum (analogous to cumsum)
5 *
6 * Compile:
7 * mex cummax.c
8 */
9
10 #include "mex.h"
11
12 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
13 {
14 /* Declare variables */
15 int n; /* number of elements */
16 double *pi; /* input array */
17 double *po1, *po2; /* output array(s) */
18 double currentMax;
19 double currentMaxPointer;
20 int i;
21
22 if (nrhs != 1) {
23 mexErrMsgTxt("Only one input argument is required.");
24 }
25 if (nlhs > 2) {
26 mexErrMsgTxt("Too many output arguments.");
27 }
28
29 if (!(mxIsDouble(prhs[0]))) {
30 mexErrMsgTxt("Input array must be of type double.");
31 }
32
33 n = mxGetNumberOfElements(prhs[0]);
34 pi = (double *)mxGetPr(prhs[0]);
35
36 plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL);
37 po1 = mxGetPr(plhs[0]);
38
39 plhs[1] = mxCreateDoubleMatrix(1, n, mxREAL);
40 po2 = mxGetPr(plhs[1]);
41
42 /* Now for the meat */
43
44 currentMax = pi[0];
45 currentMaxPointer = 1;
46 for (i = 0; i < n; i++) {
47 if (pi[i] > currentMax) {
48 currentMax = pi[i];
49 currentMaxPointer = i + 1;
50 }
51 po1[i] = currentMax;
52 po2[i] = currentMaxPointer;
53 }
54
55 mxSetN(plhs[0], n);
56 mxSetN(plhs[1], n);
57
58 }