comparison libinterp/corefcn/data.cc @ 30891:79b3c0b5c265

maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
author Rik <rik@octave.org>
date Mon, 04 Apr 2022 11:16:29 -0700
parents 3a15bf04cb7f
children 1a3cc2811090
comparison
equal deleted inserted replaced
30890:ac478fdded94 30891:79b3c0b5c265
7243 7243
7244 %!error sort () 7244 %!error sort ()
7245 %!error sort (1, 2, 3, 4) 7245 %!error sort (1, 2, 3, 4)
7246 */ 7246 */
7247 7247
7248 // Sort the rows of the matrix @var{a} according to the order
7249 // specified by @var{mode}, which can either be 'ascend' or 'descend'
7250 // and return the index vector corresponding to the sort order.
7251 //
7252 // This function does not yet support sparse matrices.
7253
7254 // FIXME: Is this function used anymore? 12/14/2015
7255 DEFUN (__sort_rows_idx__, args, ,
7256 doc: /* -*- texinfo -*-
7257 @deftypefn {} {} __sort_rows_idx__ (@var{a}, @var{mode})
7258 Undocumented internal function.
7259 @end deftypefn */)
7260 {
7261 int nargin = args.length ();
7262
7263 if (nargin < 1 || nargin > 2)
7264 print_usage ();
7265
7266 if (nargin == 2 && ! args(1).is_string ())
7267 error ("__sort_rows_idx__: second argument must be a string");
7268
7269 sortmode smode = ASCENDING;
7270 if (nargin > 1)
7271 {
7272 std::string mode = args(1).string_value ();
7273 if (mode == "ascend")
7274 smode = ASCENDING;
7275 else if (mode == "descend")
7276 smode = DESCENDING;
7277 else
7278 error (R"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
7279 }
7280
7281 octave_value arg = args(0);
7282
7283 if (arg.issparse ())
7284 error ("__sort_rows_idx__: sparse matrices not yet supported");
7285
7286 if (arg.ndims () != 2)
7287 error ("__sort_rows_idx__: needs a 2-D object");
7288
7289 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
7290
7291 // This cannot be ovl(), relies on special overloaded octave_value call.
7292 return octave_value (idx, true, true);
7293 }
7294
7248 static sortmode 7295 static sortmode
7249 get_sort_mode_option (const octave_value& arg) 7296 get_sort_mode_option (const octave_value& arg)
7250 { 7297 {
7251 // FIXME: we initialize to UNSORTED here to avoid a GCC warning 7298 // FIXME: we initialize to UNSORTED here to avoid a GCC warning
7252 // about possibly using sortmode uninitialized. 7299 // about possibly using sortmode uninitialized.