comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
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 -DNAN_EQUALS_ZERO cummax.c
8 */
9
10 #include "mex.h"
11
12
13 #if NAN_EQUALS_ZERO
14 #define IsNonZero(d) ((d) != 0.0 || mxIsNan(d))
15 #else
16 #define IsNonZero(d) ((d) != 0.0)
17 #endif
18
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21 /* Declare variables */
22 int n; /* number of elements */
23 double *pi; /* input array */
24 double *po1, *po2; /* output array(s) */
25 double currentMax;
26 double currentMaxPointer;
27 int i;
28
29 if (nrhs != 1) {
30 mexErrMsgTxt("Only one input argument is required.");
31 }
32 if (nlhs > 2) {
33 mexErrMsgTxt("Too many output arguments.");
34 }
35
36 if (!(mxIsDouble(prhs[0]))) {
37 mexErrMsgTxt("Input array must be of type double.");
38 }
39
40 n = mxGetNumberOfElements(prhs[0]);
41 pi = (double *)mxGetPr(prhs[0]);
42
43 plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL);
44 po1 = mxGetPr(plhs[0]);
45
46 plhs[1] = mxCreateDoubleMatrix(1, n, mxREAL);
47 po2 = mxGetPr(plhs[1]);
48
49 /* Now for the meat */
50
51 currentMax = pi[0];
52 currentMaxPointer = 1;
53 for (i = 0; i < n; i++) {
54 if (pi[i] > currentMax) {
55 currentMax = pi[i];
56 currentMaxPointer = i + 1;
57 }
58 po1[i] = currentMax;
59 po2[i] = currentMaxPointer;
60 }
61
62 mxSetN(plhs[0], n);
63 mxSetN(plhs[1], n);
64
65 }