diff liboctave/Sparse.cc @ 6092:30beea6739da

[project @ 2006-10-25 23:45:16 by jwe]
author jwe
date Wed, 25 Oct 2006 23:45:16 +0000
parents 802aec2b1a2e
children 9e70afeb2ebf
line wrap: on
line diff
--- a/liboctave/Sparse.cc
+++ b/liboctave/Sparse.cc
@@ -2387,6 +2387,8 @@
     {
       (*current_liboctave_error_handler)
         ("A(I, J) = X: can only have 1 or 2 indexes for sparse matrices");
+
+      lhs.clear_index ();
       return 0;
     }
 
@@ -2471,11 +2473,6 @@
 
 		      Sparse<LT> stmp (new_nr, new_nc, new_nzmx);
 
-		      // Started with an empty matrix. Now that we know
-		      // the assignment will succeed, resize lhs 
-		      if (lhs_nr <= 0 || lhs_nc <= 0)
-			lhs = Sparse<RT>(n, m);
-
 		      octave_idx_type jji = 0;
 		      octave_idx_type jj = idx_j.elem (jji);
 		      octave_idx_type kk = 0;
@@ -2487,8 +2484,9 @@
 			      octave_idx_type iii = 0;
 			      octave_idx_type ii = idx_i.elem (iii);
 			      octave_idx_type ppp = 0;
-			      octave_idx_type ppi = lhs.cidx(j+1) - 
-				lhs.cidx(j); 
+			      octave_idx_type ppi = (j >= lhs_nc ? 0 : 
+						     lhs.cidx(j+1) - 
+						     lhs.cidx(j));
 			      octave_idx_type pp = (ppp < ppi ? 
 						    lhs.ridx(lhs.cidx(j)+ppp) :
 						    new_nr);
@@ -2628,11 +2626,6 @@
 
 		      Sparse<LT> stmp (new_nr, new_nc, new_nzmx);
 
-		      // Started with an empty matrix. Now that we know
-		      // the assignment will succeed, resize lhs 
-		      if (lhs_nr <= 0 || lhs_nc <= 0)
-			lhs = Sparse<RT>(n, m);
-
 		      octave_idx_type jji = 0;
 		      octave_idx_type jj = idx_j.elem (jji);
 		      octave_idx_type kk = 0;
@@ -2644,8 +2637,9 @@
 			      octave_idx_type iii = 0;
 			      octave_idx_type ii = idx_i.elem (iii);
 			      octave_idx_type ppp = 0;
-			      octave_idx_type ppi = lhs.cidx(j+1) -
-				lhs.cidx(j);
+			      octave_idx_type ppi = (j >= lhs_nc ? 0 : 
+						     lhs.cidx(j+1) - 
+						     lhs.cidx(j));
 			      octave_idx_type pp = (ppp < ppi ? 
 						    lhs.ridx(lhs.cidx(j)+ppp) :
 						    new_nr);