ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dmat29.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00017 dvector VEC(const dmatrix& _m)
00018   {
00019     dmatrix& m= (dmatrix&) _m;
00020     int i;
00021     int mmin=m.indexmin();
00022     int mmax=m.indexmax();
00023     int ii=0;
00024     ivector io(mmin-1,mmax);
00025     io(mmin-1)=0;
00026     for (i=mmin;i<=mmax;i++)
00027     {
00028       ii+=m(i).indexmax()-m(i).indexmin()+1;
00029       io(i)=ii;
00030     }
00031     dvector tmp(1,ii);
00032     for (i=mmin;i<=mmax;i++)
00033     {
00034       tmp(io(i-1)+1,io(i)).shift(m(i).indexmin())=m(i);
00035     }
00036     return tmp;
00037   }
00038 
00045 dmatrix MAT(const dvector& v, int n, int m)
00046   {
00047     dmatrix tmp(1,n,1,m);
00048     int mmin=v.indexmin();
00049     int mmax=v.indexmax();
00050     int ii=mmin;
00051     if ( mmax-mmin+1 != n*m)
00052     {
00053       cerr << " Vector and Matrix sizes don't match in function MAT" << endl;
00054       tmp.initialize();
00055       return tmp;
00056     }
00057     for (int i=1;i<=n;i++)
00058     {
00059       for (int j=1;j<=m;j++)
00060       {
00061         tmp(i,j)=v(ii++);
00062       }
00063     }
00064     return tmp;
00065   }