6 void sumsq(
double* xsq,
double* x,
int n,
int m) {
13 #pragma omp parallel for shared(xsq,x,n,m) private(i,j)
20 xsq[j] += x[j*n+i]*x[j*n+i];
25 sprintf(temp,
"j(m)=%d(%d), i(n)=%d(%d), x=%.12f\n", j, m, i, n, x[j*n+i]);
32 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[] ) {
33 double *x, *y, *res, gamma, hlp;
74 gamma = mxGetScalar(mxGetProperty(prhs[0], 0,
"Gamma"));
77 sprintf(temp,
"Gamma=%.12f\n", gamma);
84 plhs[0] = mxCreateDoubleMatrix(m, m, mxREAL);
85 res = mxGetPr(plhs[0]);
88 sprintf(temp,
"Call with one parameter!\n");
97 #pragma omp parallel for shared(res,xsq,x,n,m) private(hlp,i,j,l)
98 for (i = 1; i < m; i++) {
99 for (j = 0; j < i; j++) {
101 for (l = 0; l < n; l++) {
103 sprintf(temp,
"ScaP i=%d, j=%d, l=%d, x=%.12f, y=%.12f\n", i, j, l, x[i*n+l], y[j*n+l]);
106 hlp += x[i*n+
l]*x[j*n+
l];
109 sprintf(temp,
"xsq[i]=%.12f, xsq[j]=%.12f, x*y=%.12f\n", xsq[i], xsq[j], hlp);
112 res[i+j*m] = exp(-(xsq[i]+xsq[j]-2*hlp)/gamma);
114 res[j+i*m] = res[i+j*m];
123 sprintf(temp,
"Call with two parameters!\n");
126 if (n != mxGetM(prhs[2]))
127 mexErrMsgTxt(
"GaussKernel.evaluate (mex): Array dimensions must match");
130 y = mxGetPr(prhs[2]);
132 plhs[0] = mxCreateDoubleMatrix(m, k, mxREAL);
133 res = mxGetPr(plhs[0]);
140 #pragma omp parallel for shared(res,xsq,ysq,x,y,n,m,k) private(hlp,i,j,l)
141 for (i = 0; i < m; i++) {
142 for (j = 0; j <
k; j++) {
144 for (l = 0; l < n; l++) {
146 sprintf(temp,
"ScaP i=%d, j=%d, l=%d, x=%.12f, y=%.12f\n", i, j, l, x[i*n+l], y[j*n+l]);
149 hlp += x[i*n+
l]*y[j*n+
l];
152 sprintf(temp,
"xsq=%.12f, ysq=%.12f, x*y=%.12f\n", xsq[i], ysq[j], hlp);
155 res[i+j*m] = exp(-(xsq[i]+ysq[j]-2*hlp)/gamma);
159 #pragma omp parallel for shared(res,xsq,ysq,x,y,n,m,k) private(hlp,i,j,l)
160 for (j = 0; j <
k; j++) {
161 for (i = 0; i < m; i++) {
163 for (l = 0; l < n; l++) {
165 sprintf(temp,
"ScaP i=%d, j=%d, l=%d, x=%.12f, y=%.12f\n", i, j, l, x[i*n+l], y[j*n+l]);
168 hlp += x[i*n+
l]*y[j*n+
l];
171 sprintf(temp,
"xsq=%.12f, ysq=%.12f, x*y=%.12f\n", xsq[i], ysq[j], hlp);
174 res[i+j*m] = exp(-(xsq[i]+ysq[j]-2*hlp)/gamma);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void sumsq(double *xsq, double *x, int n, int m)