/****************************************************************** * mexProd2nz: compute the elements of P whose positions are * specified by the variable list. * * P = mexProd2nz(blk,A,B,list), where P = A'*B. * * output: P is sparse, where * P(i,j) = * * The variable list must have its 2nd column sorted in ascending * order. The first and second column of list indicate the row * and column indices of elements of P to be computed. * * E.g. list = [1 1] * [2 2] * [3 2] * [2 3] * * SDPT3: version 3.0 * Copyright (c) 1997 by * K.C. Toh, M.J. Todd, R.H. Tutuncu * Last Modified: 2 Feb 01 ******************************************************************/ #include #include /********************************************************** * realdot: **********************************************************/ double realdot(const double *x, const int idx1, const double *y, const int idx2, const int n) { int i; double r; r=0.0; for(i=0; i< n-3; i++){ /* LEVEL 4 */ r+= x[i+idx1] * y[i+idx2]; i++; r+= x[i+idx1] * y[i+idx2]; i++; r+= x[i+idx1] * y[i+idx2]; i++; r+= x[i+idx1] * y[i+idx2]; } if(i < n-1){ /* LEVEL 2 */ r+= x[i+idx1] * y[i+idx2]; i++; r+= x[i+idx1] * y[i+idx2]; i++; } if(i < n){ /* LEVEL 1 */ r+= x[i+idx1] * y[i+idx2]; } return r; } /********************************************************** * B dense * A = nxp, B = nxp * P(i,j) = **********************************************************/ void prod1(int m, int n, int p, double *A, int *irA, int *jcA, int isspA, double *B, double *P, int *irP, int *jcP, int *list1, int *list2, int len) { int j, k, r, t, rn, jn, jold, kstart, kend, idx, count; double tmp; jold = -1; count = 0; for (t=0; t **********************************************************/ void prod2(int m, int n, int p, double *A, int *irA, int *jcA, int isspA, double *B, int *irB, int *jcB, int isspB, double *P, int *irP, int *jcP, double *Btmp, int *list1, int *list2, int len) { int j, k, r, t, rn, jn, jold, kstart, kend, idx, count; double tmp; jold = -1; count = 0; for (t=0; t2){ mexErrMsgTxt("mexProd2nz: requires 1 output argument."); } /***********************************************/ A = mxGetPr(prhs[1]); isspA = mxIsSparse(prhs[1]); m1 = mxGetM(prhs[1]); n1 = mxGetN(prhs[1]); if (isspA) { irA = mxGetIr(prhs[1]); jcA = mxGetJc(prhs[1]); } B = mxGetPr(prhs[2]); isspB = mxIsSparse(prhs[2]); m2 = mxGetM(prhs[2]); n2 = mxGetN(prhs[2]); if (isspB) { irB = mxGetIr(prhs[2]); jcB = mxGetJc(prhs[2]); } if (m1!=m2) { mexErrMsgTxt("mexProd2nz: A, B are not compatible"); } mlist = mxGetM(prhs[3]); nlist = mxGetN(prhs[3]); if (nlist != 2 ) { mexErrMsgTxt("mexProd2nz: list must have 2 columns");} listtmp = mxGetPr(prhs[3]); list1 = mxCalloc(mlist,sizeof(int)); list2 = mxCalloc(mlist,sizeof(int)); for (k=0; k