From owner-bug-octave at bevo dot che dot wisc dot edu Mon May 12 15:20:22 1997 Subject: What appears to be a matrix indexing bug From: "John W. Eaton" To: nick dot weir at gs dot com (Nick Weir) Cc: bug-octave at bevo dot che dot wisc dot edu Date: Mon, 12 May 1997 15:19:20 -0500 On 12-May-1997, Nick Weir wrote: | The attached file is a matrix, alpha.dat. I find that the following | code does not behave as one would hope: | | alpha = aload("alpha.dat"); | sortedAlpha = alpha(:,[1 2 3 4 7 5 6 8]); | | Namely, sortedAlpha appears no different that alpha (at least on my | machine). Please try the following patch. Thanks, jwe Mon May 12 02:14:13 1997 John W. Eaton * idx-vector.cc (IDX_VEC_REP::is_colon_equiv): Make it work when the vector is not sorted. *** liboctave/idx-vector.cc~ Fri Feb 21 17:45:49 1997 --- liboctave/idx-vector.cc Mon May 12 15:11:20 1997 *************** *** 449,476 **** { colon_equiv = 1; } ! else if (len > 0 && len > 1 && ! one_zero) { - int *tmp_data = copy_data (data, len); - - int tmp_len = len; - if (sort_uniq) { sort_data (tmp_data, len); ! tmp_len = make_uniq (tmp_data, len); ! } ! colon_equiv = ((tmp_len == 0 && n == 0) ! || (tmp_len == n && tmp_data[0] == 0 ! && tmp_data[tmp_len-1] == tmp_len - 1)); ! delete [] tmp_data; } else ! colon_equiv = (len == 1 && n == 1 && data[0] == 0); colon_equiv_checked = 1; } --- 449,487 ---- { colon_equiv = 1; } ! else if (len > 1 && ! one_zero) { if (sort_uniq) { + int *tmp_data = copy_data (data, len); + sort_data (tmp_data, len); ! int tmp_len = make_uniq (tmp_data, len); ! colon_equiv = (tmp_len == n && tmp_data[0] == 0 ! && tmp_data[tmp_len-1] == tmp_len - 1); ! delete [] tmp_data; ! } ! else ! { ! if (len == n) ! { ! colon_equiv = 1; ! ! for (int ii = 0; ii < n; ii++) ! if (data[ii] != ii) ! { ! colon_equiv = 0; ! break; ! } ! } ! } } else ! colon_equiv = (len == n && (n == 0 || (n == 1 && data[0] == 0))); colon_equiv_checked = 1; }