ADMB Documentation  11.1.2246
 All Classes Files Functions Variables Typedefs Friends Defines
dmat29.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmat29.cpp 1657 2014-02-19 23:22:28Z johnoel $
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     ii=0;
00033     for (i=mmin;i<=mmax;i++)
00034     {
00035       tmp(io(i-1)+1,io(i)).shift(m(i).indexmin())=m(i);
00036     }
00037     return tmp;
00038   }
00039 
00046 dmatrix MAT(const dvector& v, int n, int m)
00047   {
00048     dmatrix tmp(1,n,1,m);
00049     int mmin=v.indexmin();
00050     int mmax=v.indexmax();
00051     int ii=mmin;
00052     if ( mmax-mmin+1 != n*m)
00053     {
00054       cerr << " Vector and Matrix sizes don't match in function MAT" << endl;
00055       tmp.initialize();
00056       return tmp;
00057     }
00058     for (int i=1;i<=n;i++)
00059     {
00060       for (int j=1;j<=m;j++)
00061       {
00062         tmp(i,j)=v(ii++);
00063       }
00064     }
00065     return tmp;
00066   }