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