/* IO(1) */

vector sort_rows( matrix _w, vector _s)
{
/* produce sorted row indices from _s = sort(_w) */

  int r = rows(_w);
  int c = cols(_w);
  vector RR;

  RR = reshape(1:r,c,r)';
  RR = RR(:);
 
  return RR(_s);
}

vector sort_cols( matrix _w, vector _s)
{
/* produce sorted column indices from _s = sort(_w) */

  int r = rows(_w);
  int c = cols(_w);
  vector CC;

  CC = reshape(1:c,1,r*c);

  return CC(_s);
}
