ADMB Documentation  11.1.2503
 All Classes Files Functions Variables Typedefs Friends Defines
ivect6.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: ivect6.cpp 2407 2014-09-24 23:12:02Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 
00013 #ifndef OPT_LIB
00014   #include <cassert>
00015   #include <climits>
00016 #endif
00017 
00023 int sum(const ivector &v)
00024 {
00025   int value = 0;
00026   for (int i = v.indexmin(); i <= v.indexmax(); i++)
00027   {
00028     value += v.elem(i);
00029   }
00030   return value;
00031 }
00039 ivector pow(const ivector& v1, int x)
00040 {
00041   ivector tmp(v1.indexmin(),v1.indexmax());
00042   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00043   {
00044 #if defined(_MSC_VER) || defined(__SUNPRO_CC)
00045     double value = pow(double(v1.elem(i)),x);
00046 #else
00047     double value = pow(v1.elem(i),x);
00048 #endif
00049 
00050 #ifndef OPT_LIB
00051     assert(value <= (double)INT_MAX);
00052 #endif
00053 
00054     tmp.elem(i) = (int)value;
00055   }
00056   return tmp;
00057 }
00065 ivector pow(int x, const ivector& v1)
00066 {
00067   ivector tmp(v1.indexmin(), v1.indexmax());
00068   for (int i = v1.indexmin(); i <= v1.indexmax(); i++)
00069   {
00070 #if defined(_MSC_VER) || defined(__SUNPRO_CC)
00071     double value = pow(double(x), v1.elem(i));
00072 #else
00073     double value = pow(x, v1.elem(i));
00074 #endif
00075 
00076 #ifndef OPT_LIB
00077     assert(value <= (double)INT_MAX);
00078 #endif
00079 
00080     tmp.elem(i) = (int)value;
00081   }
00082   return tmp;
00083 }