ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
imsort.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  * Author: David Fournier
00004  *
00005  * Copyright (c) 2009-2012 ADMB Foundation
00006  */
00011 #include <fvar.hpp>
00012 
00017 imatrix sort(const imatrix& m, int col, int NSTACK)
00018 {
00019   ivector ind(m.rowmin(),m.rowmax());
00020   ivector ind1(m.rowmin(),m.rowmax());
00021   ivector ind2(m.rowmin(),m.rowmax());
00022   int i;
00023   for (i=m.rowmin();i<=m.rowmax();i++)
00024   {
00025     ind1(i)=m(i).indexmin();
00026     ind2(i)=m(i).indexmax();
00027   }
00028   //const ivector& iv=column(m,col);
00029   sort(column(m,col),ind);
00030   imatrix tmp(m.rowmin(),m.rowmax(),ind1,ind2);
00031   for (i=m.rowmin();i<=m.rowmax();i++)
00032   {
00033     tmp(i)=m(ind(i));
00034   }
00035   return tmp;
00036 }