ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat1.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 
7 #ifdef DIAG
8  int heapcheck();
9  #define _HEAPCORRUPT 1
10 #endif
11 
18 dvector operator*(const dvector& A, const dmatrix& B)
19 {
20 #ifdef DIAG
21  if(heapcheck() == _HEAPCORRUPT && ad_printf)
22  {
23  (*ad_printf)( "Entering dvector * dvec dmat is corrupted.\n" );
24  }
25  else
26  {
27  (*ad_printf)( "Entering dvector * dvec dmat Heap is OK.\n" );
28  }
29 #endif
30 
31  int imin = A.indexmin();
32  int imax = A.indexmax();
33  int jmin = B.colmin();
34  int jmax = B.colmax();
35 
36 #ifndef OPT_LIB
37  if (imin != B.rowmin() || imax != B.rowmax())
38  {
39  cerr << " Incompatible array bounds in "
40  << "dvector operator*(const dvector& A, const dmatrix& B)\n";
41  ad_exit(1);
42  }
43 #endif
44 
45  dvector results(jmin, jmax);
46 
47  double* presultsj = results.get_v() + jmin;
48  for (int j = jmin; j <= jmax; ++j)
49  {
50  *presultsj = 0.0;
51 
52  const double* pAi = A.get_v() + imin;
53  const dvector* pBi = &B(imin);
54  for (int i = imin; i <= imax; ++i)
55  {
56  *presultsj += *pAi * *(pBi->get_v() + j);
57 
58  ++pAi;
59  ++pBi;
60  }
61  ++presultsj;
62  }
63 #ifdef DIAG
64  if (heapcheck() == _HEAPCORRUPT && ad_printf)
65  {
66  (*ad_printf)( "Leaving dvector * dvec dmat is corrupted.\n" );
67  }
68  else
69  {
70  (*ad_printf)( "Leaving dvector * dvec dmat Heap is OK.\n" );
71  }
72 #endif
73 
74  return results;
75 }
82 dvector operator*(const dmatrix& A, const dvector& B)
83 {
84 #ifdef DIAG
85  if (heapcheck() == _HEAPCORRUPT && ad_printf)
86  {
87  (*ad_printf)("Entering dvector * dmat dvec is corrupted.\n");
88  }
89  else
90  {
91  (*ad_printf)("Entering dvector * dmat dvec Heap is OK.\n");
92  }
93 #endif
94 
95  int imin = A.rowmin();
96  int imax = A.rowmax();
97  int jmin = B.indexmin();
98  int jmax = B.indexmax();
99 
100 #ifndef OPT_LIB
101  if (jmin != A.colmin() || jmax != A.colmax())
102  {
103  cerr << " Incompatible array bounds in "
104  << "dvector operator*(const dmatrix& A, const dvector& B)\n";
105  ad_exit(1);
106  }
107 #endif
108 
109  dvector results(imin, imax);
110 
111  double* presultsi = results.get_v() + imin;
112  const dvector* pAi = &A(imin);
113  for (int i = imin; i <= imax; ++i)
114  {
115  *presultsi = 0.0;
116 
117  double* pBj = B.get_v() + jmin;
118  double* pAij = pAi->get_v() + jmin;
119  for (int j = jmin; j <= jmax; ++j)
120  {
121  *presultsi += *pAij * *pBj;
122 
123  ++pBj;
124  ++pAij;
125  }
126  ++presultsi;
127  ++pAi;
128  }
129 
130 #ifdef DIAG
131  if (heapcheck() == _HEAPCORRUPT && ad_printf)
132  {
133  (*ad_printf)("Leaving dvector * dmat dvec is corrupted.\n");
134  }
135  else
136  {
137  (*ad_printf)("Leaving dvector * dmat dvec Heap is OK.\n");
138  }
139 #endif
140 
141  return results;
142 }
149 dmatrix operator*(const dmatrix& A, const dmatrix& B)
150 {
151  int imin = A.rowmin();
152  int imax = A.rowmax();
153  int jmin = B.colmin();
154  int jmax = B.colmax();
155 #ifndef OPT_LIB
156  //if (imin != jmin || imax != jmax)
157  if (A.colmin() != B.rowmin() || A.colmax() != B.rowmax())
158  {
159  cerr << " Incompatible array bounds in "
160  << "dmatrix operator*(const dmatrix& A, const dmatrix& B)\n";
161  ad_exit(1);
162  }
163 #endif
164 
165  dmatrix results(imin, imax, jmin, jmax);
166  for (int j = jmin; j <= jmax; ++j)
167  {
168  dvector col = column(B, j);
169  const dvector* pAi = &A(imin);
170  dvector* presultsi = &results(imin);
171  for (int i = imin; i <= imax; ++i)
172  {
173  *(presultsi->get_v() + j) = *pAi * col;
174 
175  ++pAi;
176  ++presultsi;
177  }
178  }
179  return results;
180 }
181 /*
182 dmatrix operator*(const dmatrix& m1, const dmatrix& m2 )
183  {
184  if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
185  {
186  cerr << " Incompatible array bounds in "
187  "dmatrix operator * (const dmatrix& x, const dmatrix& m)\n";
188  ad_exit(21);
189  }
190 
191  dmatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
192 
193  double sum;
194  const double ** temp_col=
195  (const double **) malloc(m2.rowsize() * sizeof(double **));
196  temp_col-=m2.rowmin();
197 
198 
199  for (int j=m2.colmin(); j<=m2.colmax(); j++)
200  {
201  for (int k=m2.rowmin(); k<=m2.rowmax(); k++)
202  {
203  temp_col[k]=&(m2.elem(k,j));
204  }
205 
206  for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
207  {
208  sum=0;
209 
210  const dvector& temp_row = m1.elem(i);
211 
212  for (k=m1.colmin(); k<=m1.colmax(); k++)
213  {
214  sum+=temp_row.elem(k) * *(temp_col[k]);
215  }
216  tmp.elem(i,j)=sum;
217  }
218  }
219  temp_col+=m2.rowmin();
220  free ((char*)temp_col);
221  return(tmp);
222  }
223 */
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
exitptr ad_exit
Definition: gradstrc.cpp:53
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
int heapcheck(void)
Does nothing.
int rowmax() const
Definition: fvar.hpp:2929
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int colmin(void) const
Definition: fvar.hpp:2939
Description not yet available.
Definition: fvar.hpp:2819
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
double *& get_v(void)
Definition: dvector.h:148
int rowmin() const
Definition: fvar.hpp:2925
int ad_printf(FILE *stream, const char *format, Args...args)
Definition: fvar.hpp:9487
int colmax(void) const
Definition: fvar.hpp:2943