ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
imat7.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 #include "admb_messages.h"
00013 
00018 int sum(const imatrix& m)
00019 {
00020   int ssum=0;
00021   int mmin=m.rowmin();
00022   int mmax=m.rowmax();
00023   for (int i=mmin;i<=mmax;i++)
00024   {
00025     ssum+=sum(m(i));
00026   }
00027   return ssum;
00028 }
00029 
00034 int colsum(const imatrix& m, int col)
00035 {
00036   if (col < m.colmin() || col > m.colmax())
00037   {
00038     //JCA: Should be Column out of bounds
00039     ADMB_ARRAY_BOUNDS_ERROR("Row out of bounds",
00040     "int colsum(const imatrix& m,int col)", m.colmin(), m.colmax(), col);
00041   }
00042   int isum=0;
00043   int mmin=m.rowmin();
00044   int mmax=m.rowmax();
00045   for (int i=mmin;i<=mmax;i++)
00046   {
00047     isum+=m(i,col);
00048   }
00049   return isum;
00050 }
00051 
00058 ivector column(const imatrix& m, int col)
00059 {
00060   if (col < m.colmin() || col > m.colmax())
00061   {
00062     //JCA: Should be Column out of bounds
00063     ADMB_ARRAY_BOUNDS_ERROR("Row out of bounds",
00064     "int colsum(const imatrix& m,int col)", m.colmin(), m.colmax(), col);
00065   }
00066   int mmin=m.rowmin();
00067   int mmax=m.rowmax();
00068   ivector tmp(mmin,mmax);
00069   for (int i=mmin;i<=mmax;i++)
00070   {
00071     tmp(i)=m(i,col);
00072   }
00073   return tmp;
00074 }