[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problem with non-sorted indices in l.h. sides of assignements
From: |
John W. Eaton |
Subject: |
problem with non-sorted indices in l.h. sides of assignements |
Date: |
Thu, 31 Jul 1997 23:17:31 -0500 |
On 29-Jul-1997, Mario Storti <address@hidden> wrote:
| (Octave 2.0.5 in Linux/Pentium an Digital Unix/Alpha.)
|
| Is this a bug? Should the vector of indices be sorted in the left hand
| side of an assignment?
|
| > octave> a=(1:10)'
| > a =
| >
| > 1
| > 2
| > 3
| > 4
| > 5
| > 6
| > 7
| > 8
| > 9
| > 10
| >
| > octave> a([1 3 2])=[]
| > a =
| >
| > 2
| > 4
| > 5
| > 6
| > 7
| > 8
| > 9
| > 10
| >
| > octave>
| >
|
| But if I sort the index vector the second element also is eliminated:
|
| > octave> a([1 2 3])=[]
| > a =
| >
| > 4
| > 5
| > 6
| > 7
| > 8
| > 9
| > 10
| >
|
| I expected that the result should be independent of the sorting of the
| index vector. (I'm not sure but I think that Matlab works this way.) I
| read the chapter "Assignment Ops" in the on-line manual and it isn't
| explicitly stated that the index vector has to be sorted.
Yes, it's a bug. Please try the following patch.
Thanks,
jwe
Thu Jul 31 22:13:54 1997 John W. Eaton <address@hidden>
* idx-vector.cc (IDX_VEC_REP::sort): New function.
* idx-vector.h (idx_vector::sort): Ditto.
* Array2-idx.h (Array2<T>::maybe_delete_elements): Use it before
trying to delete elements specified by the index vectors.
*** liboctave/idx-vector.cc~ Mon May 19 16:14:36 1997
--- liboctave/idx-vector.cc Thu Jul 31 22:13:53 1997
***************
*** 490,495 ****
--- 490,504 ----
}
void
+ IDX_VEC_REP::sort (bool uniq)
+ {
+ sort_data (data, len);
+
+ if (uniq)
+ len = make_uniq (data, len);
+ }
+
+ void
IDX_VEC_REP::shorten (int n)
{
if (n > 0 && n <= len)
*** liboctave/idx-vector.h~ Mon May 19 17:40:15 1997
--- liboctave/idx-vector.h Thu Jul 31 22:13:21 1997
***************
*** 94,99 ****
--- 94,101 ----
int is_colon (void) const { return colon; }
int is_colon_equiv (int n, int sort_uniq);
+ void sort (bool uniq);
+
int orig_rows (void) const { return orig_nr; }
int orig_columns (void) const { return orig_nc; }
***************
*** 213,218 ****
--- 215,222 ----
int is_colon (void) const { return rep->is_colon (); }
int is_colon_equiv (int n, int sort_uniq = 0) const
{ return rep->is_colon_equiv (n, sort_uniq); }
+
+ void sort (bool uniq = false) { rep->sort (uniq); }
int orig_rows (void) const { return rep->orig_rows (); }
int orig_columns (void) const { return rep->orig_columns (); }
*** liboctave/Array2-idx.h~ Tue Jun 10 11:05:05 1997
--- liboctave/Array2-idx.h Thu Jul 31 22:15:29 1997
***************
*** 226,231 ****
--- 226,233 ----
resize (0, 0);
else
{
+ idx_j.sort (true);
+
int num_to_delete = idx_j.length (nc);
if (num_to_delete != 0)
***************
*** 288,293 ****
--- 290,297 ----
resize (0, 0);
else
{
+ idx_i.sort (true);
+
int num_to_delete = idx_i.length (nr);
if (num_to_delete != 0)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- problem with non-sorted indices in l.h. sides of assignements,
John W. Eaton <=