ADMB Documentation  11.1.2274
 All Classes Files Functions Variables Typedefs Friends Defines
imat10.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: imat10.cpp 1713 2014-03-01 00:26:20Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00017 ivector diagonal(const imatrix& m)
00018 {
00019   if (m.indexmin() != m.colmin() || m.indexmax() != m.colmax())
00020   {
00021     cerr << "Error matrix not square in function diagonal" << endl;
00022     exit(21);
00023   }
00024   int mmin=m.indexmin();
00025   int mmax=m.indexmax();
00026   ivector tmp(mmin,mmax);
00027   for (int i=mmin;i<=mmax;i++)
00028     tmp(i)=m(i,i);
00029   return tmp;
00030 }
00031 
00036  imatrix  operator * (const imatrix& m1,const imatrix& m2 )
00037  {
00038    if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
00039    {
00040      cerr << " Incompatible array bounds in "
00041      "imatrix  operator * (const imatrix& x, const imatrix& m)\n";
00042      ad_exit(21);
00043    }
00044    imatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
00045    //double sum;
00046    for (int j=m2.colmin(); j<=m2.colmax(); j++)
00047    {
00048      dvector m2col=column(m2,j);
00049      for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00050      {
00051        tmp(i,j)=m1(i) * m2col;
00052      }
00053    }
00054    return(tmp);
00055  }