ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_ma3.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 /*
14 dvar_vector operator*(const dvar_vector& x, const dmatrix& m)
15  {
16  RETURN_ARRAYS_INCREMENT();
17 
18  if (x.indexmin() != m.rowmin() || x.indexmax() != m.rowmax())
19  {
20  cerr << " Incompatible array bounds in dvar_vector operator * (const dvar_vector& x,const dmatrix& m)\n";
21  ad_exit(21);
22  }
23  dvar_vector tmp(m.colmin(),m.colmax());
24 
25  for (int j=m.colmin(); j<=m.colmax(); j++)
26  {
27  tmp[j]=0.0;
28  for (int i=x.indexmin(); i<=x.indexmax(); i++)
29  {
30  tmp[j]+=x[i]*m[i][j];
31  }
32  //cout << "tmp[j]= "<< value(tmp[j])<<"\n";
33  }
34  RETURN_ARRAYS_DECREMENT();
35  return(tmp);
36  }
37 
38 dvar_vector operator*(const dmatrix& m, const dvar_vector& x)
39  {
40  RETURN_ARRAYS_INCREMENT();
41 
42  if (x.indexmin() != m.colmin() || x.indexmax() != m.colmax())
43  {
44  cerr << " Incompatible array bounds in dvar_vector operator*(const dvar_vector& x, const dmatrix& m)\n";
45  ad_exit(21);
46  }
47 
48  dvar_vector tmp(m.rowmin(),m.rowmax());
49 
50  for (int i=m.rowmin(); i<=m.rowmax(); i++)
51  {
52  tmp[i]=0.0;
53  for (int j=x.indexmin(); j<=x.indexmax(); j++)
54  {
55  tmp[i]+=m[i][j]*x[j];
56  }
57  }
58  RETURN_ARRAYS_DECREMENT();
59  return(tmp);
60  }
61 */
62 
68 {
71 
72  int min = m1.rowmin();
73  int max = m1.rowmax();
74 
75  dvariable tmp;
76  tmp = 0.0;
77 
78  const dvar_vector* pm1i = &m1(min);
79  for (int i = min; i <= max; ++i)
80  {
81  tmp += norm2(*pm1i);
82 
83  ++pm1i;
84  }
85 
86  if (tmp > 0.0)
87  {
88  tmp = pow(tmp, 0.5);
89  }
90  else
91  {
92  tmp = 0.0;
93  }
95  return tmp;
96 }
97 
99 {
102 
103  int min = m1.rowmin();
104  int max = m1.rowmax();
105 
106  dvariable tmp;
107  tmp = 0.0;
108 
109  const dvar_vector* pm1i = &m1(min);
110  for (int i = min; i <= max; ++i)
111  {
112  tmp += norm2(*pm1i);
113 
114  ++pm1i;
115  }
116 
118  return tmp;
119 }
120 dvariable sumsq(const dvar_matrix& m1) {return(norm2(m1));}
121 
122  /*
123  dvar_matrix trans(const dvar_matrix& m1)
124  {
125  RETURN_ARRAYS_INCREMENT();
126 
127  dvar_matrix tmp(m1.colmin(),m1.colmax(),m1.rowmin(),m1.rowmax());
128 
129  for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
130  {
131  for (int j=m1.colmin(); j<=m1.colmax(); j++)
132  {
133  tmp.elem(j,i)=m1.elem(i,j);
134  }
135  }
136  RETURN_ARRAYS_DECREMENT();
137  return (tmp);
138  }
139  */
140 
int rowmax(void) const
Definition: fvar.hpp:2564
double sumsq(const d3_array &a)
Definition: d3arr2a.cpp:181
ADMB variable vector.
Definition: fvar.hpp:2172
double norm(const d3_array &a)
Return computed norm value of a.
Definition: d3arr2a.cpp:190
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
#define min(a, b)
Definition: cbivnorm.cpp:188
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
int rowmin(void) const
Definition: fvar.hpp:2560
double norm2(const d3_array &a)
Return sum of squared elements in a.
Definition: d3arr2a.cpp:167
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
#define max(a, b)
Definition: cbivnorm.cpp:189
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17