[Scipy-svn] r4152 - trunk/scipy/sparse/sparsetools

scipy-svn@scip... scipy-svn@scip...
Fri Apr 18 14:03:33 CDT 2008


Author: wnbell
Date: 2008-04-18 14:03:29 -0500 (Fri, 18 Apr 2008)
New Revision: 4152

Modified:
   trunk/scipy/sparse/sparsetools/bsr.h
   trunk/scipy/sparse/sparsetools/csr.h
Log:
fixed memory access errors reported in ticket #616


Modified: trunk/scipy/sparse/sparsetools/bsr.h
===================================================================
--- trunk/scipy/sparse/sparsetools/bsr.h	2008-04-18 03:15:07 UTC (rev 4151)
+++ trunk/scipy/sparse/sparsetools/bsr.h	2008-04-18 19:03:29 UTC (rev 4152)
@@ -468,11 +468,11 @@
         I A_end = Ap[i+1];
         I B_end = Bp[i+1];
 
-        I A_j = Aj[A_pos];
-        I B_j = Bj[B_pos];
-            
         //while not finished with either row
         while(A_pos < A_end && B_pos < B_end){
+            I A_j = Aj[A_pos];
+            I B_j = Bj[B_pos];
+
             if(A_j == B_j){
                 for(I n = 0; n < RC; n++){
                     result[n] = op(Ax[RC*A_pos + n],Bx[RC*B_pos + n]);
@@ -484,9 +484,8 @@
                     nnz++;
                 }
 
-                A_j = Aj[++A_pos]; 
-                B_j = Bj[++B_pos];
-
+                A_pos++; 
+                B_pos++;
             } else if (A_j < B_j) {
                 for(I n = 0; n < RC; n++){
                     result[n] = op(Ax[RC*A_pos + n],0);
@@ -498,8 +497,7 @@
                     nnz++;
                 }
 
-                A_j = Aj[++A_pos]; 
-
+                A_pos++; 
             } else {
                 //B_j < A_j
                 for(I n = 0; n < RC; n++){
@@ -511,26 +509,23 @@
                     nnz++;
                 }
 
-                B_j = Bj[++B_pos];
-
+                B_pos++;
             }
         }
 
         //tail
         while(A_pos < A_end){
-
             for(I n = 0; n < RC; n++){
                 result[n] = op(Ax[RC*A_pos + n],0);
             }
 
             if(is_nonzero_block(result,RC)){
-                Cj[nnz] = A_j;
+                Cj[nnz] = Aj[A_pos];
                 result += RC;
                 nnz++;
             }
 
-            A_j = Aj[++A_pos]; 
-
+            A_pos++; 
         }
         while(B_pos < B_end){
             for(I n = 0; n < RC; n++){
@@ -538,13 +533,12 @@
             }
 
             if(is_nonzero_block(result,RC)){
-                Cj[nnz] = B_j;
+                Cj[nnz] = Bj[B_pos];
                 result += RC;
                 nnz++;
             }
 
-            B_j = Bj[++B_pos];
-
+            B_pos++;
         }
 
         Cp[i+1] = nnz;

Modified: trunk/scipy/sparse/sparsetools/csr.h
===================================================================
--- trunk/scipy/sparse/sparsetools/csr.h	2008-04-18 03:15:07 UTC (rev 4151)
+++ trunk/scipy/sparse/sparsetools/csr.h	2008-04-18 19:03:29 UTC (rev 4152)
@@ -630,11 +630,11 @@
         I A_end = Ap[i+1];
         I B_end = Bp[i+1];
 
-        I A_j = Aj[A_pos];
-        I B_j = Bj[B_pos];
-
         //while not finished with either row
         while(A_pos < A_end && B_pos < B_end){
+            I A_j = Aj[A_pos];
+            I B_j = Bj[B_pos];
+
             if(A_j == B_j){
                 T result = op(Ax[A_pos],Bx[B_pos]);
                 if(result != 0){
@@ -642,8 +642,8 @@
                     Cx[nnz] = result;
                     nnz++;
                 }
-                A_j = Aj[++A_pos]; 
-                B_j = Bj[++B_pos];
+                A_pos++;
+                B_pos++;
             } else if (A_j < B_j) {
                 T result = op(Ax[A_pos],0);
                 if (result != 0){
@@ -651,7 +651,7 @@
                     Cx[nnz] = result;
                     nnz++;
                 }
-                A_j = Aj[++A_pos]; 
+                A_pos++; 
             } else {
                 //B_j < A_j
                 T result = op(0,Bx[B_pos]);
@@ -660,7 +660,7 @@
                     Cx[nnz] = result;
                     nnz++;
                 }
-                B_j = Bj[++B_pos];
+                B_pos++;
             }
         }
 
@@ -759,7 +759,7 @@
             I j = Aj[jj];
             T x = Ax[jj];
             jj++;
-            while( Aj[jj] == j && jj < row_end ){
+            while( jj < row_end && Aj[jj] == j ){
                 x += Ax[jj];
                 jj++;
             }



More information about the Scipy-svn mailing list