1 #include "BSprivate.h" 2 3 /*@ BSmat_subtract - Subtract shift*B from A 4 5 Input Parameters: 6 . A - a sparse matrix 7 . B - a sparse matrix 8 . shift - the multiple of B to subtract from A 9 10 Returns: 11 void 12 13 @*/ BSmat_subtract(BSspmat * A,BSspmat * B,FLOAT shift)14void BSmat_subtract(BSspmat *A, BSspmat *B, FLOAT shift) 15 { 16 int i; 17 BSsprow **Arows = A->rows; 18 BSsprow **Brows = B->rows; 19 int *colA, *colB; 20 int lenA, lenB; 21 FLOAT *nzA, *nzB; 22 int indA, indB; 23 24 if (shift == 0.0) return; 25 26 for (i=0;i<A->num_rows;i++) { 27 indA = 0; 28 indB = 0; 29 lenA = Arows[i]->length; 30 lenB = Brows[i]->length; 31 colA = Arows[i]->col; 32 colB = Brows[i]->col; 33 nzA = Arows[i]->nz; 34 nzB = Brows[i]->nz; 35 while ((indA < lenA) && (indB < lenB)) { 36 if (colA[indA] == colB[indB]) { 37 nzA[indA] -= (nzB[indB]*shift); 38 indA++; 39 indB++; 40 } else if (colA[indA] > colB[indB]) { 41 indB++; 42 } else { 43 indA++; 44 } 45 } 46 } 47 } 48