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