Mercurial > hg > octave-lyh
changeset 7064:faff87ff9d5a
[project @ 2007-10-24 21:09:43 by dbateman]
author | dbateman |
---|---|
date | Wed, 24 Oct 2007 21:09:44 +0000 |
parents | 58102cc15ddf |
children | 97db94ae2cf0 |
files | src/ChangeLog src/DLD-FUNCTIONS/sort.cc src/ov-intx.h src/ov.cc src/ov.h |
diffstat | 5 files changed, 363 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2007-10-24 David Bateman <dbateman@free.fr> + + * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::OCTAVE_VALUE_INT_MATRIX_T + (const ArrayN<OCTAVE_INT_T>&)): New constructor. + * ov.cc (octave_value::octave_value(const ArrayN<T>) with T being + octave_int8, octave_uint8, octave_int16, octave_uint16, + octave_int32, octave_uint32, octave_int64, octave_uint64): New + constructors. + * ov.h (octave_value::octave_value(const ArrayN<T>) with T being + octave_int8, octave_uint8, octave_int16, octave_uint16, + octave_int32, octave_uint32, octave_int64, octave_uint64): + Declare them. + * DLD-FUNCTIONS/sort.cc (template class octave_sort<T>, + template class vec_index<T>, template class + octave_sort<vec_index<T> *>, with T being + octave_int8, octave_uint8, octave_int16, octave_uint16, + octave_int32, octave_uint32, octave_int64, octave_uint64): New + instantiations of sort template classes. + (Fsort): Use them. + 2007-10-24 John W. Eaton <jwe@octave.org> * graphics.cc (root_figure::properties::set_currentfigure):
--- a/src/DLD-FUNCTIONS/sort.cc +++ b/src/DLD-FUNCTIONS/sort.cc @@ -890,6 +890,198 @@ mx_sort_indexed (ArrayN<char> &m, int dim, sortmode mode); #endif +template class octave_sort<octave_int8>; +template class vec_index<octave_int8>; +template class octave_sort<vec_index<octave_int8> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int8 a, octave_int8 b); + +bool +ascending_compare (vec_index<octave_int8> *a, vec_index<octave_int8> *b); + +bool +descending_compare (octave_int8 a, octave_int8 b); + +bool +descending_compare (vec_index<octave_int8> *a, vec_index<octave_int8> *b); + +static octave_value_list +mx_sort (ArrayN<octave_int8> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_int8> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_uint8>; +template class vec_index<octave_uint8>; +template class octave_sort<vec_index<octave_uint8> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint8 a, octave_uint8 b); + +bool +ascending_compare (vec_index<octave_uint8> *a, vec_index<octave_uint8> *b); + +bool +descending_compare (octave_uint8 a, octave_uint8 b); + +bool +descending_compare (vec_index<octave_uint8> *a, vec_index<octave_uint8> *b); + +static octave_value_list +mx_sort (ArrayN<octave_uint8> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_uint8> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_int16>; +template class vec_index<octave_int16>; +template class octave_sort<vec_index<octave_int16> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int16 a, octave_int16 b); + +bool +ascending_compare (vec_index<octave_int16> *a, vec_index<octave_int16> *b); + +bool +descending_compare (octave_int16 a, octave_int16 b); + +bool +descending_compare (vec_index<octave_int16> *a, vec_index<octave_int16> *b); + +static octave_value_list +mx_sort (ArrayN<octave_int16> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_int16> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_uint16>; +template class vec_index<octave_uint16>; +template class octave_sort<vec_index<octave_uint16> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint16 a, octave_uint16 b); + +bool +ascending_compare (vec_index<octave_uint16> *a, vec_index<octave_uint16> *b); + +bool +descending_compare (octave_uint16 a, octave_uint16 b); + +bool +descending_compare (vec_index<octave_uint16> *a, vec_index<octave_uint16> *b); + +static octave_value_list +mx_sort (ArrayN<octave_uint16> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_uint16> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_int32>; +template class vec_index<octave_int32>; +template class octave_sort<vec_index<octave_int32> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int32 a, octave_int32 b); + +bool +ascending_compare (vec_index<octave_int32> *a, vec_index<octave_int32> *b); + +bool +descending_compare (octave_int32 a, octave_int32 b); + +bool +descending_compare (vec_index<octave_int32> *a, vec_index<octave_int32> *b); + +static octave_value_list +mx_sort (ArrayN<octave_int32> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_int32> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_uint32>; +template class vec_index<octave_uint32>; +template class octave_sort<vec_index<octave_uint32> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint32 a, octave_uint32 b); + +bool +ascending_compare (vec_index<octave_uint32> *a, vec_index<octave_uint32> *b); + +bool +descending_compare (octave_uint32 a, octave_uint32 b); + +bool +descending_compare (vec_index<octave_uint32> *a, vec_index<octave_uint32> *b); + +static octave_value_list +mx_sort (ArrayN<octave_uint32> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_uint32> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_int64>; +template class vec_index<octave_int64>; +template class octave_sort<vec_index<octave_int64> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int64 a, octave_int64 b); + +bool +ascending_compare (vec_index<octave_int64> *a, vec_index<octave_int64> *b); + +bool +descending_compare (octave_int64 a, octave_int64 b); + +bool +descending_compare (vec_index<octave_int64> *a, vec_index<octave_int64> *b); + +static octave_value_list +mx_sort (ArrayN<octave_int64> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_int64> &m, int dim, sortmode mode); +#endif + +template class octave_sort<octave_uint64>; +template class vec_index<octave_uint64>; +template class octave_sort<vec_index<octave_uint64> *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint64 a, octave_uint64 b); + +bool +ascending_compare (vec_index<octave_uint64> *a, vec_index<octave_uint64> *b); + +bool +descending_compare (octave_uint64 a, octave_uint64 b); + +bool +descending_compare (vec_index<octave_uint64> *a, vec_index<octave_uint64> *b); + +static octave_value_list +mx_sort (ArrayN<octave_uint64> &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN<octave_uint64> &m, int dim, sortmode mode); +#endif + template <> bool ascending_compare (vec_index<octave_value> *a, vec_index<octave_value> *b) @@ -1048,6 +1240,10 @@ } } + // FIXME Perhaps sort should be made a method of the octave_value classes + // and then the mess of if statements both might be replaced with + // retval = arg.sort (dim, smode, return_idx); + if (arg.is_real_type ()) { if (arg.is_sparse_type ()) @@ -1062,6 +1258,94 @@ retval = mx_sort_sparse (m, dim, smode); } } + else if (arg.is_int8_type ()) + { + int8NDArray m = arg.int8_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_uint8_type ()) + { + uint8NDArray m = arg.uint8_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_int16_type ()) + { + int16NDArray m = arg.int16_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_uint16_type ()) + { + uint16NDArray m = arg.uint16_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_int32_type ()) + { + int32NDArray m = arg.int32_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_uint32_type ()) + { + uint32NDArray m = arg.uint32_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_int64_type ()) + { + int64NDArray m = arg.int64_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } + else if (arg.is_uint64_type ()) + { + uint64NDArray m = arg.uint64_array_value (); + if (! error_state) + { + if (return_idx) + retval = mx_sort_indexed (m, dim, smode); + else + retval = mx_sort (m, dim, smode); + } + } else { NDArray m = arg.array_value ();
--- a/src/ov-intx.h +++ b/src/ov-intx.h @@ -50,6 +50,9 @@ OCTAVE_VALUE_INT_MATRIX_T (const OCTAVE_INT_NDARRAY_T& nda) : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> (nda) { } + OCTAVE_VALUE_INT_MATRIX_T (const ArrayN<OCTAVE_INT_T>& nda) + : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> (OCTAVE_INT_NDARRAY_T (nda)) { } + ~OCTAVE_VALUE_INT_MATRIX_T (void) { } octave_base_value *clone (void) const
--- a/src/ov.cc +++ b/src/ov.cc @@ -612,48 +612,96 @@ maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_int8>& inda) + : rep (new octave_int8_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const uint8NDArray& inda) : rep (new octave_uint8_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_uint8>& inda) + : rep (new octave_uint8_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const int16NDArray& inda) : rep (new octave_int16_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_int16>& inda) + : rep (new octave_int16_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const uint16NDArray& inda) : rep (new octave_uint16_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_uint16>& inda) + : rep (new octave_uint16_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const int32NDArray& inda) : rep (new octave_int32_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_int32>& inda) + : rep (new octave_int32_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const uint32NDArray& inda) : rep (new octave_uint32_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_uint32>& inda) + : rep (new octave_uint32_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const int64NDArray& inda) : rep (new octave_int64_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_int64>& inda) + : rep (new octave_int64_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (const uint64NDArray& inda) : rep (new octave_uint64_matrix (inda)) { maybe_mutate (); } +octave_value::octave_value (const ArrayN<octave_uint64>& inda) + : rep (new octave_uint64_matrix (inda)) +{ + maybe_mutate (); +} + octave_value::octave_value (double base, double limit, double inc) : rep (new octave_range (base, limit, inc)) {
--- a/src/ov.h +++ b/src/ov.h @@ -207,13 +207,21 @@ octave_value (const octave_uint32& i); octave_value (const octave_uint64& i); octave_value (const int8NDArray& inda); + octave_value (const ArrayN<octave_int8>& inda); octave_value (const int16NDArray& inda); + octave_value (const ArrayN<octave_int16>& inda); octave_value (const int32NDArray& inda); + octave_value (const ArrayN<octave_int32>& inda); octave_value (const int64NDArray& inda); + octave_value (const ArrayN<octave_int64>& inda); octave_value (const uint8NDArray& inda); + octave_value (const ArrayN<octave_uint8>& inda); octave_value (const uint16NDArray& inda); + octave_value (const ArrayN<octave_uint16>& inda); octave_value (const uint32NDArray& inda); + octave_value (const ArrayN<octave_uint32>& inda); octave_value (const uint64NDArray& inda); + octave_value (const ArrayN<octave_uint64>& inda); octave_value (double base, double limit, double inc); octave_value (const Range& r); octave_value (const Octave_map& m);