ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imat10.cpp
Go to the documentation of this file.
1 
5 #include "fvar.hpp"
6 
12 ivector diagonal(const imatrix& matrix)
13 {
14  int min = matrix.rowmin();
15  int max = matrix.rowmax();
16  if (min != matrix.colmin() || max != matrix.colmax())
17  {
18  cerr << "Error: imatrix is not square"
19  << " in diagonal(const imatrix&).\n";
20  ad_exit(1);
21  }
22  ivector vector(min, max);
23  for (int i = min; i <= max; ++i)
24  {
25  vector(i) = matrix(i,i);
26  }
27  return vector;
28 }
38 int operator*(const ivector& t1, const ivector& t2)
39 {
40  if (t1.indexmin() != t2.indexmin() || t1.indexmax() != t2.indexmax())
41  {
42  cerr << "Index bounds do not match"
43  << " in operator*(const ivector&, const ivector&)\n";
44  ad_exit(1);
45  }
46  int tmp = 0;
47 #ifdef OPT_LIB
48  const int* pt1=&t1[t1.indexmin()];
49  const int* pt1m=&t1[t1.indexmax()];
50  const int* pt2=&t2[t2.indexmin()];
51  do
52  {
53  tmp+=*pt1++ * *pt2++;
54  }
55  while (pt1<=pt1m);
56 
57 #else
58  #ifndef USE_ASSEMBLER
59  int min=t1.indexmin();
60  int max=t1.indexmax();
61  for (int i=min; i<=max; i++)
62  {
63  tmp+=t1[i]*t2[i];
64  }
65  #else
66  int min=t1.indexmin();
67  int n=t1.indexmax()-min+1;
68  dp_dotproduct(&tmp,&(t1(min)),&(t2(min)),n);
69  #endif
70 #endif
71 
72  return tmp;
73 }
80 imatrix operator*(const imatrix& a, const imatrix& b)
81 {
82  int min = a.rowmin();
83  int max = a.rowmax();
84  if (min != b.colmin() || max != b.colmax())
85  {
86  cerr << " Incompatible array bounds"
87  << " in operator*(const imatrix&, const imatrix&)\n";
88  ad_exit(1);
89  }
90  imatrix results(min, max, min, max);
91  for (int j = min; j <= max; ++j)
92  {
93  ivector col = column(b, j);
94  for (int i = min; i <= max; ++i)
95  {
96  results(i, j) = a(i) * col;
97  }
98  }
99  return results;
100 }
Description not yet available.
Definition: imatrix.h:69
dvector diagonal(const dmatrix &matrix)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat31.cpp:12
int rowmin() const
Definition: imatrix.h:146
exitptr ad_exit
Definition: gradstrc.cpp:53
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
#define min(a, b)
Definition: cbivnorm.cpp:188
int colmin(void) const
Definition: imatrix.h:155
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
int colmax(void) const
Definition: imatrix.h:159
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
#define max(a, b)
Definition: cbivnorm.cpp:189
int rowmax() const
Definition: imatrix.h:150