# HG changeset patch # User dbateman # Date 1193260184 0 # Node ID faff87ff9d5a2fd33cb0aa0a21dcc2f0edd82a76 # Parent 58102cc15ddf15ead43c9ff8cf4de86267811f76 [project @ 2007-10-24 21:09:43 by dbateman] diff -r 58102cc15ddf -r faff87ff9d5a src/ChangeLog --- a/src/ChangeLog Wed Oct 24 20:35:20 2007 +0000 +++ b/src/ChangeLog Wed Oct 24 21:09:44 2007 +0000 @@ -1,3 +1,23 @@ +2007-10-24 David Bateman + + * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::OCTAVE_VALUE_INT_MATRIX_T + (const ArrayN&)): New constructor. + * ov.cc (octave_value::octave_value(const ArrayN) 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) 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, + template class vec_index, template class + octave_sort *>, 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 * graphics.cc (root_figure::properties::set_currentfigure): diff -r 58102cc15ddf -r faff87ff9d5a src/DLD-FUNCTIONS/sort.cc --- a/src/DLD-FUNCTIONS/sort.cc Wed Oct 24 20:35:20 2007 +0000 +++ b/src/DLD-FUNCTIONS/sort.cc Wed Oct 24 21:09:44 2007 +0000 @@ -890,6 +890,198 @@ mx_sort_indexed (ArrayN &m, int dim, sortmode mode); #endif +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int8 a, octave_int8 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_int8 a, octave_int8 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint8 a, octave_uint8 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_uint8 a, octave_uint8 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int16 a, octave_int16 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_int16 a, octave_int16 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint16 a, octave_uint16 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_uint16 a, octave_uint16 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int32 a, octave_int32 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_int32 a, octave_int32 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint32 a, octave_uint32 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_uint32 a, octave_uint32 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_int64 a, octave_int64 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_int64 a, octave_int64 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + +template class octave_sort; +template class vec_index; +template class octave_sort *>; + +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +bool +ascending_compare (octave_uint64 a, octave_uint64 b); + +bool +ascending_compare (vec_index *a, vec_index *b); + +bool +descending_compare (octave_uint64 a, octave_uint64 b); + +bool +descending_compare (vec_index *a, vec_index *b); + +static octave_value_list +mx_sort (ArrayN &m, int dim, sortmode mode); + +static octave_value_list +mx_sort_indexed (ArrayN &m, int dim, sortmode mode); +#endif + template <> bool ascending_compare (vec_index *a, vec_index *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 (); diff -r 58102cc15ddf -r faff87ff9d5a src/ov-intx.h --- a/src/ov-intx.h Wed Oct 24 20:35:20 2007 +0000 +++ b/src/ov-intx.h Wed Oct 24 21:09:44 2007 +0000 @@ -50,6 +50,9 @@ OCTAVE_VALUE_INT_MATRIX_T (const OCTAVE_INT_NDARRAY_T& nda) : octave_base_int_matrix (nda) { } + OCTAVE_VALUE_INT_MATRIX_T (const ArrayN& nda) + : octave_base_int_matrix (OCTAVE_INT_NDARRAY_T (nda)) { } + ~OCTAVE_VALUE_INT_MATRIX_T (void) { } octave_base_value *clone (void) const diff -r 58102cc15ddf -r faff87ff9d5a src/ov.cc --- a/src/ov.cc Wed Oct 24 20:35:20 2007 +0000 +++ b/src/ov.cc Wed Oct 24 21:09:44 2007 +0000 @@ -612,48 +612,96 @@ maybe_mutate (); } +octave_value::octave_value (const ArrayN& 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& 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& 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& 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& 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& 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& 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& 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)) { diff -r 58102cc15ddf -r faff87ff9d5a src/ov.h --- a/src/ov.h Wed Oct 24 20:35:20 2007 +0000 +++ b/src/ov.h Wed Oct 24 21:09:44 2007 +0000 @@ -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& inda); octave_value (const int16NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const int32NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const int64NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const uint8NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const uint16NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const uint32NDArray& inda); + octave_value (const ArrayN& inda); octave_value (const uint64NDArray& inda); + octave_value (const ArrayN& inda); octave_value (double base, double limit, double inc); octave_value (const Range& r); octave_value (const Octave_map& m);