ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m43.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 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     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 
00046 dvar_matrix MAT(const dvar_vector& v, int n, int m)
00047   {
00048     dvar_matrix 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   }