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