ADMB Documentation  11.1.1932
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m43.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_m43.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00017 dvar_vector VEC(const dvar_matrix& _m)
00018   {
00019     dvar_matrix& m= (dvar_matrix&) _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     dvar_vector 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 
00047 dvar_matrix MAT(const dvar_vector& v, int n, int m)
00048   {
00049     dvar_matrix tmp(1,n,1,m);
00050     int mmin=v.indexmin();
00051     int mmax=v.indexmax();
00052     int ii=mmin;
00053     if ( mmax-mmin+1 != n*m)
00054     {
00055       cerr << " Vector and Matrix sizes don't match in function MAT" << endl;
00056       tmp.initialize();
00057       return tmp;
00058     }
00059     for (int i=1;i<=n;i++)
00060     {
00061       for (int j=1;j<=m;j++)
00062       {
00063         tmp(i,j)=v(ii++);
00064       }
00065     }
00066     return tmp;
00067   }