KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dontuse_evaluateDirect.c
Go to the documentation of this file.
1 #include <mex.h>
2 #include <math.h>
3 #include <omp.h>
4 
5 void mexFunction( int nlhs, mxArray *plhs[],
6  int nrhs, const mxArray *prhs[] )
7 {
8  double *x, *y, *res, gamma, hlp;
9 
10  int cur, i, j, k, l, m, n, n2;
11 
12  /* const mxArray *net; */
13 
14  /*
15  if (nrhs != 3)
16  {
17  mexErrMsgTxt("Wrong number input arguments.");
18  }
19  else if (nlhs > 1)
20  {
21  mexErrMsgTxt("Too many output arguments.");
22  }*/
23 
24  /*
25  if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]))
26  {
27  mexErrMsgTxt("x1 must be a double matrix.");
28  }
29  */
30  n = mxGetM(prhs[1]);
31  m = mxGetN(prhs[1]);
32  x = mxGetPr(prhs[1]);
33 
34  /*
35  * if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]))
36  * {
37  * mexErrMsgTxt("x2 must be a double matrix.");
38  * }
39  */
40  int sel = 2;
41  if (nrhs != 3) sel = 1;
42  n2 = mxGetM(prhs[sel]);
43  k = mxGetN(prhs[sel]);
44  y = mxGetPr(prhs[sel]);
45 
46  if (n != n2)
47  mexErrMsgTxt("GaussKernel.evaluate (mex): Array dimensions must match");
48 
49  /* Output */
50  plhs[0] = mxCreateDoubleMatrix(m, k, mxREAL);
51  res = mxGetPr(plhs[0]);
52 
53 
54  /*char temp[100];*/
55  /* Matrix computation */
56  gamma = mxGetScalar(mxGetProperty(prhs[0], 0, "Gamma"));
57 
58  if (m > k) {
59  #pragma omp parallel for private(i, j, l, cur, hlp) shared(res, gamma, x, y, m, k)
60  for (i = 0; i < m; i++) {
61  for (j = 0; j < k; j++) {
62  cur = i+j*m;
63  /*sprintf(temp,"%.12f",cur);
64  mexPrintf(temp);*/
65  for (l = 0; l < n; l++) {
66  hlp = x[i*n+l] - y[j*n+l];
67  res[cur] += hlp*hlp;
68  }
69  res[cur] = exp(-gamma*res[cur]);
70  }
71  }
72  } else {
73  #pragma omp parallel for private(i, j, l, cur, hlp) shared(res, gamma, x, y, m, k)
74  for (j = 0; j < k; j++) {
75  for (i = 0; i < m; i++) {
76  cur = i+j*m;
77  /*sprintf(temp,"%.12f",cur);
78  mexPrintf(temp);*/
79  for (l = 0; l < n; l++) {
80  hlp = x[i*n+l] - y[j*n+l];
81  res[cur] += hlp*hlp;
82  }
83  res[cur] = exp(-gamma*res[cur]);
84  }
85  }
86  }
87 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])