ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ivect6.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <fvar.hpp>
12 
13 #ifndef OPT_LIB
14  #include <cassert>
15  #include <climits>
16 #endif
17 
23 int sum(const ivector &v)
24 {
25  int min = v.indexmin();
26  int max = v.indexmax();
27  int value = 0;
28 
29  int* pvi = v.get_v() + min;
30  for (int i = min; i <= max; ++i)
31  {
32  value += *pvi;
33 
34  ++pvi;
35  }
36  return value;
37 }
45 ivector pow(const ivector& v1, int x)
46 {
47  ivector tmp(v1.indexmin(),v1.indexmax());
48  for (int i=v1.indexmin();i<=v1.indexmax();i++)
49  {
50 #if defined(_MSC_VER) || defined(__SUNPRO_CC)
51  double value = pow(double(v1.elem(i)),x);
52 #else
53  double value = pow(v1.elem(i),x);
54 #endif
55 
56 #ifndef OPT_LIB
57  assert(value <= (double)INT_MAX);
58 #endif
59 
60  tmp.elem(i) = (int)value;
61  }
62  return tmp;
63 }
71 ivector pow(int x, const ivector& v1)
72 {
73  ivector tmp(v1.indexmin(), v1.indexmax());
74  for (int i = v1.indexmin(); i <= v1.indexmax(); i++)
75  {
76 #if defined(_MSC_VER) || defined(__SUNPRO_CC)
77  double value = pow(double(x), v1.elem(i));
78 #else
79  double value = pow(x, v1.elem(i));
80 #endif
81 
82 #ifndef OPT_LIB
83  assert(value <= (double)INT_MAX);
84 #endif
85 
86  tmp.elem(i) = (int)value;
87  }
88  return tmp;
89 }
int & elem(int i)
Definition: ivector.h:90
#define x
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
int * get_v() const
Definition: ivector.h:114
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: ivector.h:99
int indexmax() const
Definition: ivector.h:104
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
#define max(a, b)
Definition: cbivnorm.cpp:189
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17