/****************************************************************** * mexProd2.c : C-MEX file to compute the product of two matrices. * * P = mexProd2(blk,A,B,type) * * input: blk = 1x2 cell array describing the block structure of A and B * A = mxn matrix. * B = nxp matrix. * type = 0 general matrix product * 1 if P is symmetric * * SDPT3: version 3.0 * Copyright (c) 1997 by * K.C. Toh, M.J. Todd, R.H. Tutuncu * Last Modified: 2 Feb 01 ******************************************************************/ #include #include /********************************************************** * saxpy: z = z + alpha*y **********************************************************/ void saxpy(double x, double *y, int idx1, double *z, int idx2, int istart, int iend) { int i; for(i=istart; i j && sym) { break; } P[ri+jm] += tmp*A[i]; } } } } if (type==1) { symmetrize(P,m); } return; } /********************************************************** * A sparse, B sparse **********************************************************/ void product4(double *A, mwIndex *irA, mwIndex *jcA, double *B, mwIndex *irB, mwIndex *jcB, double *P, mwIndex *irP, mwIndex *jcP, double *Ptmp, int numblk, int *cumblk) { int i, j, k, l, r, t, istart, iend, kstart, kend, jstart, jend; int idx; double tmp; idx = 0; jcP[0]=0; for (l=0; l2){ mexErrMsgTxt("mexProd2: requires 1 output argument."); } if (mxIsCell(prhs[1]) || mxIsCell(prhs[2])) { mexErrMsgTxt("mexProd2: 2ND and 3RD input must both be matrices"); } if (mxGetM(prhs[0]) > 1) { mexErrMsgTxt("mexProd2: blk can only have 1 row"); } /*** get pointers ***/ if (nrhs > 3) { type = (int)mxGetScalar(prhs[3]); } else { type = 0; } subs[0] = 0; subs[1] = 1; index = mxCalcSingleSubscript(prhs[0],nsubs,subs); blk_cell_pr = mxGetCell(prhs[0],index); blksize = mxGetPr(blk_cell_pr); numblk = mxGetN(blk_cell_pr); cumblk = (int*)mxCalloc(numblk+1,sizeof(int)); NZmax = 0; for (l=0; l 1) && !(isspA && isspB) && !(n1==1 && n2==1)) { mexErrMsgTxt("mexProd2: 2ND and 3RD must be both sparse"); } /***** create return argument *****/ if (isspA && isspB && !(n1==1 && n2==1)){ plhs[0] = mxCreateSparse(m1,n2,NZmax,mxREAL); P = mxGetPr(plhs[0]); irP = mxGetIr(plhs[0]); jcP = mxGetJc(plhs[0]); } else { plhs[0] = mxCreateDoubleMatrix(m1,n2,mxREAL); P = mxGetPr(plhs[0]); } if (isspA && isspB && !(n1==1 && n2==1)) { Ptmp = (double*)mxCalloc(cumblk[numblk],sizeof(double)); } /********************************************** * Do the actual computations in a subroutine **********************************************/ if (m1 == m2 && n1 == 1 && n2 == 1) { product5(A, irA, jcA, B, irB, jcB, P, m1, isspA, isspB); } else { if (!isspA && !isspB){ product(A, B, P, m1, n1, n2, type); } else if (!isspA && isspB){ product2(A, B, irB, jcB, P, m1, n1, n2, type); } else if (isspA && !isspB){ product3(A, irA, jcA, B, P, m1, n1, n2, type); } else if (isspA && isspB){ product4(A, irA, jcA, B, irB, jcB,P,irP,jcP,Ptmp,numblk,cumblk); } } mxFree(cumblk); if (isspA && isspB && !(n1==1 && n2==1)) { mxFree(Ptmp); } return; } /**********************************************************/