comparison toolboxes/FullBNT-1.0.7/KPMtools/max_mult.c @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 /* C mex version of max_mult.m in BPMRF2 directory */
2 /* gcc -Wall -I/mit/matlab_v6.5/distrib/bin/glnx86 -c max_mult.c */
3
4 #include <math.h>
5 #include "mex.h"
6
7 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
8 {
9 int rows,cols,common,m,n,p;
10 double y1, y2;
11 double *arr1, *arr2, *arr3;
12
13
14 if (nrhs!=2 || nlhs>1)
15 mexErrMsgTxt("max_mult requires two inputs and one output");
16 if (mxIsChar(prhs[0]) || mxIsClass(prhs[0], "sparse") || mxIsComplex(prhs[0])
17 || mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
18 mexErrMsgTxt("Inputs must be real, full, and nonstring");
19 if (mxGetN(prhs[0])!=mxGetM(prhs[1]))
20 mexErrMsgTxt("The number of columns of A must be the same as the number of rows of x");
21
22
23 arr1=mxGetPr(prhs[0]);
24 arr2=mxGetPr(prhs[1]);
25 p=mxGetN(prhs[0]);
26 m=mxGetM(prhs[0]);
27 n=mxGetN(prhs[1]);
28 plhs[0]=mxCreateDoubleMatrix(m, n, mxREAL);
29 arr3=mxMalloc(m*n*sizeof(double));
30
31 for (rows=0; rows<m ; rows++)
32 for (cols=0; cols<n ; cols++)
33 {
34 y1=arr1[rows]*arr2[cols*p];
35 for (common=1; common<p; common++)
36 {
37 y2=arr1[rows+common*m]*arr2[common+cols*p];
38 if (y2>y1)
39 y1=y2;
40 }
41 arr3[rows+cols*m]=y1;
42 }
43
44 mxSetPr(plhs[0], arr3);
45
46 }