ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dvect2.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>
20 dvector elem_prod(const dvector& t1, const dvector& t2)
21  {
22  int min = t1.indexmin();
23  int max = t1.indexmax();
24 #ifndef OPT_LIB
25  if (min != t2.indexmin() || max != t2.indexmax())
26  {
27  cerr << "Index bounds do not match in dvector "
28  "elem_prod(const dvector&, const dvector&)\n";
29  ad_exit(1);
30  }
31 #endif
32 
33  dvector tmp(min, max);
34 
35  double* ptmp = tmp.get_v() + min;
36  double* pt1 = t1.get_v() + min;
37  double* pt2 = t2.get_v() + min;
38  for (int i = min; i <= max; ++i)
39  {
40  //tmp[i]=t1[i]*t2[i];
41  *ptmp = *pt1 * *pt2;
42  ++ptmp;
43  ++pt1;
44  ++pt2;
45  }
46 
47  return tmp;
48  }
49 
58 dvector elem_div(const dvector& t1, const dvector& t2)
59  {
60  int min = t1.indexmin();
61  int max = t1.indexmax();
62 #ifndef OPT_LIB
63  if (min != t2.indexmin() || max != t2.indexmax())
64  {
65  cerr << "Index bounds do not match in "
66  "dvector elem_div(const dvector&, const dvector&)\n";
67  ad_exit(1);
68  }
69 #endif
70 
71  dvector tmp(min, max);
72 
73  double* ptmp = tmp.get_v() + min;
74  double* pt1 = t1.get_v() + min;
75  double* pt2 = t2.get_v() + min;
76  for (int i = min; i <= max; ++i)
77  {
78  //tmp[i]=t1[i]/t2[i];
79  *ptmp = *pt1 / *pt2;
80  ++ptmp;
81  ++pt1;
82  ++pt2;
83  }
84 
85  return tmp;
86  }
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
Definition: d3arr2a.cpp:92
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
Definition: d3arr2a.cpp:112
exitptr ad_exit
Definition: gradstrc.cpp:53
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
#define max(a, b)
Definition: cbivnorm.cpp:189
double *& get_v(void)
Definition: dvector.h:148