Mercurial > hg > camir-ismir2012
annotate toolboxes/distance_learning/mlr/util/cummax.c @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
| author | Daniel Wolff |
|---|---|
| date | Fri, 19 Aug 2016 13:07:06 +0200 |
| parents | |
| children |
| rev | line source |
|---|---|
| Daniel@0 | 1 /* CREATED:2010-01-08 17:25:37 by Brian McFee <bmcfee@cs.ucsd.edu> */ |
| Daniel@0 | 2 /* cummax.c |
| Daniel@0 | 3 * |
| Daniel@0 | 4 * cumulative maximum (analogous to cumsum) |
| Daniel@0 | 5 * |
| Daniel@0 | 6 * Compile: |
| Daniel@0 | 7 * mex -DNAN_EQUALS_ZERO cummax.c |
| Daniel@0 | 8 */ |
| Daniel@0 | 9 |
| Daniel@0 | 10 #include "mex.h" |
| Daniel@0 | 11 |
| Daniel@0 | 12 |
| Daniel@0 | 13 #if NAN_EQUALS_ZERO |
| Daniel@0 | 14 #define IsNonZero(d) ((d) != 0.0 || mxIsNan(d)) |
| Daniel@0 | 15 #else |
| Daniel@0 | 16 #define IsNonZero(d) ((d) != 0.0) |
| Daniel@0 | 17 #endif |
| Daniel@0 | 18 |
| Daniel@0 | 19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
| Daniel@0 | 20 { |
| Daniel@0 | 21 /* Declare variables */ |
| Daniel@0 | 22 int n; /* number of elements */ |
| Daniel@0 | 23 double *pi; /* input array */ |
| Daniel@0 | 24 double *po1, *po2; /* output array(s) */ |
| Daniel@0 | 25 double currentMax; |
| Daniel@0 | 26 double currentMaxPointer; |
| Daniel@0 | 27 int i; |
| Daniel@0 | 28 |
| Daniel@0 | 29 if (nrhs != 1) { |
| Daniel@0 | 30 mexErrMsgTxt("Only one input argument is required."); |
| Daniel@0 | 31 } |
| Daniel@0 | 32 if (nlhs > 2) { |
| Daniel@0 | 33 mexErrMsgTxt("Too many output arguments."); |
| Daniel@0 | 34 } |
| Daniel@0 | 35 |
| Daniel@0 | 36 if (!(mxIsDouble(prhs[0]))) { |
| Daniel@0 | 37 mexErrMsgTxt("Input array must be of type double."); |
| Daniel@0 | 38 } |
| Daniel@0 | 39 |
| Daniel@0 | 40 n = mxGetNumberOfElements(prhs[0]); |
| Daniel@0 | 41 pi = (double *)mxGetPr(prhs[0]); |
| Daniel@0 | 42 |
| Daniel@0 | 43 plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL); |
| Daniel@0 | 44 po1 = mxGetPr(plhs[0]); |
| Daniel@0 | 45 |
| Daniel@0 | 46 plhs[1] = mxCreateDoubleMatrix(1, n, mxREAL); |
| Daniel@0 | 47 po2 = mxGetPr(plhs[1]); |
| Daniel@0 | 48 |
| Daniel@0 | 49 /* Now for the meat */ |
| Daniel@0 | 50 |
| Daniel@0 | 51 currentMax = pi[0]; |
| Daniel@0 | 52 currentMaxPointer = 1; |
| Daniel@0 | 53 for (i = 0; i < n; i++) { |
| Daniel@0 | 54 if (pi[i] > currentMax) { |
| Daniel@0 | 55 currentMax = pi[i]; |
| Daniel@0 | 56 currentMaxPointer = i + 1; |
| Daniel@0 | 57 } |
| Daniel@0 | 58 po1[i] = currentMax; |
| Daniel@0 | 59 po2[i] = currentMaxPointer; |
| Daniel@0 | 60 } |
| Daniel@0 | 61 |
| Daniel@0 | 62 mxSetN(plhs[0], n); |
| Daniel@0 | 63 mxSetN(plhs[1], n); |
| Daniel@0 | 64 |
| Daniel@0 | 65 } |
