/************************************************************************ * mexschurfun(X,Y,options) * options = 1, add Y to the diagonal of X (a square matrix) * options = 2, add Y to X * options = 3, X(i,j) = X(i,j)*Y(i)*Y(j) ************************************************************************/ #include "mex.h" #include /******************************************************************** PROCEDURE mexFunction - Entry for Matlab *********************************************************************/ void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray *prhs[]) { double *X, *Y, *Ytmp; mwIndex *irX, *jcX, *irY, *jcY; int n, isspX, isspY, j, jn, k, kstart, kend, r, kstart2, kend2; int options, scalarY; double tmp, tmp2, alpha; if(nrhs < 2) mexErrMsgTxt("mexschurfun: requires at least 2 input arguments."); if(nlhs > 0) mexErrMsgTxt("mexschurfun: requires no output argument."); X = mxGetPr(prhs[0]); isspX = mxIsSparse(prhs[0]); if (isspX) { irX = mxGetIr(prhs[0]); jcX = mxGetJc(prhs[0]); } n = mxGetM(prhs[0]); if (n != mxGetN(prhs[0])) { mexErrMsgTxt("X should be square."); } isspY = mxIsSparse(prhs[1]); Y = mxGetPr(prhs[1]); if (isspY) { irY = mxGetIr(prhs[1]); jcY = mxGetJc(prhs[1]); } if (nrhs == 2) { if ((mxGetM(prhs[1]) == n) & (mxGetN(prhs[1]) == n)) { options = 2; } else { options = 1; } } else { options = (int) (*mxGetPr(prhs[2])); } if (options == 1 || options == 3) { if ((mxGetN(prhs[1]) != 1) & (mxGetM(prhs[1]) != 1)) { mexErrMsgTxt("mexschurfun: Y should be a vector."); } } else { if ((mxGetN(prhs[1]) == 1) & (mxGetM(prhs[1]) == 1)) { scalarY = 1; alpha = Y[0]; } else { scalarY = 0; } } /********************************************************/ Ytmp = (double*)mxCalloc(n,sizeof(double)); if (options==1) { if (isspY) { for (k=0; k