Mercurial > hg > octave-lyh
changeset 7463:2467639bd8c0
eliminate UNDEFINED sort mode
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 08 Feb 2008 16:00:16 -0500 |
parents | dfcaf7ed48e3 |
children | 2a1cb886ec98 |
files | liboctave/Array-d.cc liboctave/Array.cc liboctave/Array.h liboctave/Array2.h liboctave/Array3.h liboctave/ArrayN.h liboctave/ChangeLog liboctave/Range.cc liboctave/Range.h liboctave/Sparse.cc liboctave/Sparse.h liboctave/oct-sort.h src/ov-base-mat.h src/ov-base-sparse.h src/ov-base.h src/ov-range.h src/ov-str-mat.h src/ov.h |
diffstat | 18 files changed, 58 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-d.cc +++ b/liboctave/Array-d.cc @@ -107,6 +107,8 @@ lsort.set_compare (ascending_compare); else if (mode == DESCENDING) lsort.set_compare (descending_compare); + else + abort (); if (stride == 1) { @@ -133,7 +135,7 @@ if (lo_ieee_signbit (octave_NaN)) { - if (mode == UNDEFINED || mode == ASCENDING) + if (mode == ASCENDING) { octave_idx_type i = 0; double *vtmp = reinterpret_cast<double *> (p); @@ -194,7 +196,7 @@ if (lo_ieee_signbit (octave_NaN)) { - if (mode == UNDEFINED || mode == ASCENDING) + if (mode == ASCENDING) { octave_idx_type i = 0; while (xisnan (v[i++*stride + offset]) && i < ns); @@ -250,6 +252,8 @@ indexed_sort.set_compare (ascending_compare); else if (mode == DESCENDING) indexed_sort.set_compare (descending_compare); + else + abort (); OCTAVE_LOCAL_BUFFER (vec_index<uint64_t> *, vi, ns); OCTAVE_LOCAL_BUFFER (vec_index<uint64_t>, vix, ns); @@ -296,7 +300,7 @@ if (lo_ieee_signbit (octave_NaN)) { - if (mode == UNDEFINED || mode == ASCENDING) + if (mode == ASCENDING) { octave_idx_type i = 0; while (xisnan (v[i++*stride+offset]) && i < ns);
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2498,6 +2498,8 @@ lsort.set_compare (ascending_compare); else if (mode == DESCENDING) lsort.set_compare (descending_compare); + else + abort (); if (stride == 1) { @@ -2566,6 +2568,8 @@ indexed_sort.set_compare (ascending_compare); else if (mode == DESCENDING) indexed_sort.set_compare (descending_compare); + else + abort (); OCTAVE_LOCAL_BUFFER (vec_index<T> *, vi, ns); OCTAVE_LOCAL_BUFFER (vec_index<T>, vix, ns);
--- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -546,9 +546,9 @@ // You should not use it anywhere else. void *mex_get_data (void) const { return const_cast<T *> (data ()); } - Array<T> sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const; + Array<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; Array<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const; + sortmode mode = ASCENDING) const; }; // NOTE: these functions should be friends of the Array<T> class and
--- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -116,14 +116,14 @@ return Array2<T> (tmp, tmp.rows (), tmp.columns ()); } - Array2<T> sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + Array2<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (dim, mode); return Array2<T> (tmp, tmp.rows (), tmp.columns ()); } Array2<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (sidx, dim, mode); return Array2<T> (tmp, tmp.rows (), tmp.columns ());
--- a/liboctave/Array3.h +++ b/liboctave/Array3.h @@ -76,14 +76,14 @@ void resize (octave_idx_type r, octave_idx_type c, octave_idx_type p, const T& val) { this->resize_and_fill (r, c, p, val); } - Array3<T> sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + Array3<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (dim, mode); return Array3<T> (tmp, tmp.rows (), tmp.columns (), tmp.pages ()); } Array3<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (sidx, dim, mode); return Array3<T> (tmp, tmp.rows (), tmp.columns (), tmp.pages ());
--- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -136,14 +136,14 @@ return ArrayN<T> (tmp, tmp.dims ()); } - ArrayN<T> sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + ArrayN<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (dim, mode); return ArrayN<T> (tmp, tmp.dims ()); } ArrayN<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { Array<T> tmp = Array<T>::sort (sidx, dim, mode); return ArrayN<T> (tmp, tmp.dims ());
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2008-02-08 John W. Eaton <jwe@octave.org> + + * oct-sort.h (enum sortmode): Eliminate UNDEFINED. Change all + uses of UNDEFINED to ASCENDING. + 2008-02-07 John W. Eaton <jwe@octave.org> * Range.cc (Range::sort_internal): Rename from sort. New arg,
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -185,19 +185,12 @@ if (dim == 1) { - switch (mode) - { - case ASCENDING: - retval.sort_internal (true); - break; - - case DESCENDING: - retval.sort_internal (false); - break; - - default: - (*current_liboctave_error_handler) ("Range::sort: invalid sort mode"); - } + if (mode == ASCENDING) + retval.sort_internal (true); + else if (mode == DESCENDING) + retval.sort_internal (false); + else + abort (); } else if (dim != 0) (*current_liboctave_error_handler) ("Range::sort: invalid dimension"); @@ -213,19 +206,12 @@ if (dim == 1) { - switch (mode) - { - case ASCENDING: + if (mode == ASCENDING) retval.sort_internal (sidx, true); - break; - - case DESCENDING: - retval.sort_internal (sidx, false); - break; - - default: - (*current_liboctave_error_handler) ("Range::sort: invalid sort mode"); - } + else if (mode == DESCENDING) + retval.sort_internal (sidx, false); + else + abort (); } else if (dim != 0) (*current_liboctave_error_handler) ("Range::sort: invalid dimension");
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -65,10 +65,10 @@ void sort_internal (bool ascending = true); void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); - Range sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const; + Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const; + sortmode mode = ASCENDING) const; void set_base (double b) {
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -2108,6 +2108,8 @@ lsort.set_compare (sparse_ascending_compare); else if (mode == DESCENDING) lsort.set_compare (sparse_descending_compare); + else + abort (); T *v = m.data (); octave_idx_type *mcidx = m.cidx (); @@ -2175,6 +2177,8 @@ indexed_sort.set_compare (sparse_ascending_compare); else if (mode == DESCENDING) indexed_sort.set_compare (sparse_descending_compare); + else + abort (); T *v = m.data (); octave_idx_type *mcidx = m.cidx ();
--- a/liboctave/Sparse.h +++ b/liboctave/Sparse.h @@ -518,9 +518,9 @@ octave_idx_type *mex_get_jc (void) const { return const_cast<octave_idx_type *> (cidx ()); } - Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const; + Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const; + sortmode mode = ASCENDING) const; }; // NOTE: these functions should be friends of the Sparse<T> class and
--- a/liboctave/oct-sort.h +++ b/liboctave/oct-sort.h @@ -97,7 +97,7 @@ #define MERGESTATE_TEMP_SIZE 1024 // Enum for type of sort function -enum sortmode { UNDEFINED, ASCENDING, DESCENDING }; +enum sortmode { ASCENDING, DESCENDING }; template <class T> class
--- a/src/ov-base-mat.h +++ b/src/ov-base-mat.h @@ -110,10 +110,10 @@ MatrixType matrix_type (const MatrixType& _typ) const { MatrixType ret = typ; typ = _typ; return ret; } - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (matrix.sort (dim, mode)); } octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return octave_value (matrix.sort (sidx, dim, mode)); } bool is_matrix_type (void) const { return true; }
--- a/src/ov-base-sparse.h +++ b/src/ov-base-sparse.h @@ -116,10 +116,10 @@ octave_value all (int dim = 0) const { return matrix.all (dim); } octave_value any (int dim = 0) const { return matrix.any (dim); } - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (matrix.sort (dim, mode)); } octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return octave_value (matrix.sort (sidx, dim, mode)); } MatrixType matrix_type (void) const { return typ; }
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -457,10 +457,10 @@ virtual mxArray *as_mxArray (void) const; virtual octave_value sort (octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const; + sortmode mode = ASCENDING) const; virtual octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const; + sortmode mode = ASCENDING) const; protected:
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -132,11 +132,11 @@ octave_value any (int dim = 0) const; - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return range.sort (dim, mode); } octave_value sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return range.sort (sidx, dim, mode); } bool is_real_type (void) const { return true; }
--- a/src/ov-str-mat.h +++ b/src/ov-str-mat.h @@ -126,10 +126,10 @@ std::string string_value (bool force = false) const; - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (matrix.sort (dim, mode), true); } octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return octave_value (matrix.sort (sidx, dim, mode), true); } bool print_as_scalar (void) const { return (rows () <= 1); } @@ -227,10 +227,10 @@ { return do_index_op_internal (idx, resize_ok, '\''); } - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (matrix.sort (dim, mode), true, '\''); } octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return octave_value (matrix.sort (sidx, dim, mode), true, '\''); } private:
--- a/src/ov.h +++ b/src/ov.h @@ -865,10 +865,10 @@ mxArray *as_mxArray (void) const { return rep->as_mxArray (); } - octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const + octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return rep->sort (dim, mode); } octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, - sortmode mode = UNDEFINED) const + sortmode mode = ASCENDING) const { return rep->sort (sidx, dim, mode); } protected: