ADMB Documentation  11.1.2247
 All Classes Files Functions Variables Typedefs Friends Defines
dmat12.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmat12.cpp 1112 2013-07-12 21:41:41Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 
00017 dmatrix symmetrize(const dmatrix& m)
00018 {
00019   if (m.rowmin() != m.colmin() || m.rowmax() != m.colmax() )
00020   {
00021     cerr << " Non square matrix passed to dmatrix symmetrize\n";
00022     ad_exit(1);
00023   }
00024   int rmin=m.rowmin();
00025   int rmax=m.rowmax();
00026 
00027   dmatrix s(rmin,rmax,rmin,rmax);
00028   for (int i=rmin;i<=rmax;i++)
00029   {
00030     s(i,i)=m(i,i);
00031 
00032     for (int j=rmin;j<i;j++)
00033     {
00034       s(i,j)=(m(i,j)+m(j,i))/2.;
00035       s(j,i)=s(i,j);
00036     }
00037   }
00038   return s;
00039 }