# HG changeset patch # User jwe # Date 1095281375 0 # Node ID d117a9fb83be18b2891dd5eae798cdd79769e220 # Parent fcbdb120450a60699f5d4a184742c43cd7117c44 [project @ 2004-09-15 20:49:21 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,33 @@ +2004-09-15 David Bateman + + * ov.cc (octave_value::octave_value (const ArrayN&, bool)): + New Constructor . + * ov.h: Provide decl. + + * DLD-FUNCTIONS/sort.cc (sortmode): New enum to define sort direction. + (template class vec_index): New class to contain values and + index for indexed sorts, replacing all previous struct versions. + Instantiate for double, Complex, char and octave_value. + (template static octave_value_list mx_sort (ArrayN &, int, + sortmode)): New templated version of mx_sort replacing all previous + versions, but specific to non indexed sorts. Instantiate for char + and double if not IEEE754. + (template <> static octave_value_list mx_sort (ArrayN &, + int, sortmode)): Specialized function of mx_sort of IEEE754. + (template static octave_value_list mx_sort_indexed + (ArrayN &, int, sortmode)): New templated version of mx_sort + for indexed sorts. Instantiate for double, Complex, char and + octave_value. + (ascending_compare, descending_compare): Comparison functions + for double, char, vec_index *, vec_index *, + vec_index *, vec_index. Fix Complex comparison + operator to sort by arg of values if absolute values are equal. + (Fsort): Update docs for new mode argument and for sorting of + strings and cell arrays of strings. Implement mode argument to + define ascending and descending sorts. Include sorting of cell + arrays of strings. Adapt for new templated versions of the mx_sort + function. + 2004-09-15 John W. Eaton * ov-cell.cc (octave_cell::subsref): Pass nargout to next_subsref. diff --git a/src/DLD-FUNCTIONS/sort.cc b/src/DLD-FUNCTIONS/sort.cc --- a/src/DLD-FUNCTIONS/sort.cc +++ b/src/DLD-FUNCTIONS/sort.cc @@ -38,13 +38,13 @@ #include "ov-cell.h" #include "oct-sort.cc" -enum sortmode {UNDEFINED, ASCENDING, DESCENDING}; +enum sortmode { UNDEFINED, ASCENDING, DESCENDING }; template class vec_index { - public: +public: T vec; int indx; }; @@ -74,11 +74,13 @@ sort.set_compare (descending_compare); if (stride == 1) - for (unsigned int j = 0; j < iter; j++) - { - sort.sort (v, ns); - v += ns; - } + { + for (unsigned int j = 0; j < iter; j++) + { + sort.sort (v, ns); + v += ns; + } + } else { OCTAVE_LOCAL_BUFFER (T, vi, ns); @@ -103,7 +105,8 @@ } } - retval (0) = octave_value (m); + retval(0) = octave_value (m); + return retval; } @@ -190,8 +193,8 @@ } } - retval (1) = idx; - retval (0) = octave_value (m); + retval(1) = idx; + retval(0) = octave_value (m); return retval; } @@ -301,7 +304,7 @@ { unsigned int i = 0; double *vtmp = (double *)p; - while (xisnan(vtmp[i++]) && i < ns); + while (xisnan (vtmp[i++]) && i < ns); for (unsigned int l = 0; l < ns - i + 1; l++) vtmp[l] = vtmp[l+i-1]; for (unsigned int l = ns - i + 1; l < ns; l++) @@ -350,7 +353,7 @@ (! lo_ieee_signbit (octave_NaN) && (mode == DESCENDING))) { unsigned int i = 0; - while (xisnan(v[i++*stride + offset]) && i < ns); + while (xisnan (v[i++*stride + offset]) && i < ns); for (unsigned int l = 0; l < ns - i + 1; l++) v[l*stride + offset] = v[(l+i-1)*stride + offset]; for (unsigned int l = ns - i + 1; l < ns; l++) @@ -437,7 +440,7 @@ (! lo_ieee_signbit (octave_NaN) && (mode == DESCENDING))) { unsigned int i = 0; - while (xisnan(v[i++*stride+offset]) && i < ns); + while (xisnan (v[i++*stride+offset]) && i < ns); OCTAVE_LOCAL_BUFFER (double, itmp, i - 1); for (unsigned int l = 0; l < i -1; l++) itmp[l] = idx(l*stride + offset); @@ -454,8 +457,8 @@ } } - retval (1) = idx; - retval (0) = m; + retval(1) = idx; + retval(0) = m; return retval; } @@ -464,25 +467,25 @@ bool ascending_compare (double a, double b) { - return (xisnan(b) || (a < b)); + return (xisnan (b) || (a < b)); } bool ascending_compare (vec_index *a, vec_index *b) { - return (xisnan(b->vec) || (a->vec < b->vec)); + return (xisnan (b->vec) || (a->vec < b->vec)); } bool descending_compare (double a, double b) { - return (xisnan(a) || (a > b)); + return (xisnan (a) || (a > b)); } bool descending_compare (vec_index *a, vec_index *b) { - return (xisnan(a->vec) || (a->vec > b->vec)); + return (xisnan (a->vec) || (a->vec > b->vec)); } template class octave_sort; @@ -508,15 +511,19 @@ bool ascending_compare (vec_index *a, vec_index *b) { - return (xisnan(b->vec) || (xabs(a->vec) < xabs(b->vec)) || - ((xabs(a->vec) == xabs(b->vec)) && (arg(a->vec) < arg(b->vec)))); + return (xisnan (b->vec) + || (xabs (a->vec) < xabs (b->vec)) + || ((xabs (a->vec) == xabs (b->vec)) + && (arg (a->vec) < arg (b->vec)))); } bool descending_compare (vec_index *a, vec_index *b) { - return (xisnan(a->vec) || (xabs(a->vec) > xabs(b->vec)) || - ((xabs(a->vec) == xabs(b->vec)) && (arg(a->vec) > arg(b->vec)))); + return (xisnan (a->vec) + || (xabs (a->vec) > xabs (b->vec)) + || ((xabs (a->vec) == xabs (b->vec)) + && (arg (a->vec) > arg (b->vec)))); } template class vec_index; diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -597,6 +597,15 @@ maybe_mutate (); } +octave_value::octave_value (const ArrayN& chm, bool is_str) + : rep (is_str + ? new octave_char_matrix_str (chm) + : new octave_char_matrix (chm)) +{ + rep->count = 1; + maybe_mutate (); +} + octave_value::octave_value (const octave_int8& i) : rep (new octave_int8_scalar (i)) { diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -217,6 +217,7 @@ octave_value (const string_vector& s); octave_value (const charMatrix& chm, bool is_string = false); octave_value (const charNDArray& chnda, bool is_string = false); + octave_value (const ArrayN& chnda, bool is_string = false); octave_value (const octave_int8& i); octave_value (const octave_int16& i); octave_value (const octave_int32& i);