ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat4.cpp
Go to the documentation of this file.
1 
6 #if (__cplusplus > 199711L)
7  #include <iterator>
8  #include <algorithm>
9 #endif
10 
11 #include "fvar.hpp"
12 
17 struct dvec_ptr_ptr
18 {
19  void** m;
20 };
21 
28 {
29  if (allocated(*this))
30  {
31  if (rowmin() != other.rowmin() || rowmax() != other.rowmax()
32  || colmin() != other.colmin() || colmax() != other.colmax())
33  {
34  cerr << "Incompatible array bounds in "
35  << "dmatrix& dmatrix::operator=(const dmatrix&)\n";
36  ad_exit(1);
37  }
38  // check for condition that both matrices point to the same object
39  if (m != other.m)
40  {
41 #if (__cplusplus <= 199711L)
42  for (int i = rowmin(); i <= rowmax(); ++i)
43  {
44  *(m+i) = other[i];
45  }
46 #else
47  dvector* iter = other.begin();
48  std::for_each(begin(), end(), [&iter](dvector& v) {
49  v = *iter;
50  ++iter;
51  });
52 #endif
53  }
54  }
55  else
56  {
57  index_min = other.index_min;
58  index_max = other.index_max;
59  shape = other.shape;
60  if (shape)
61  {
62  (shape->ncopies)++;
63  }
64  m = other.m;
65  }
66  return *this;
67 }
74 {
75  if (rowmin() != other.rowmin() || rowmax() != other.rowmax() )
76  {
77  cerr << "Incompatible array bounds in "
78  << "dmatrix& dmatrix::operator+=(const dmatrix&)\n";
79  ad_exit(1);
80  }
81 #if (__cplusplus <= 199711L)
82  for (int i = rowmin(); i <= rowmax(); ++i)
83  {
84  elem(i) += other.elem(i);
85  }
86 #else
87  dvector* iter = other.begin();
88  std::for_each(begin(), end(), [&iter](dvector& v) {
89  v += *iter;
90  ++iter;
91  });
92 #endif
93  return *this;
94 }
101 {
102  if (rowmin() != other.rowmin() || rowmax() != other.rowmax() )
103  {
104  cerr << "Incompatible array bounds in "
105  << "dmatrix& dmatrix::operator-=(const dmatrix&)\n";
106  ad_exit(1);
107  }
108 #if (__cplusplus <= 199711L)
109  for (int i = rowmin(); i <= rowmax(); ++i)
110  {
111  elem(i) -= other.elem(i);
112  }
113 #else
114  dvector* iter = other.begin();
115  std::for_each(begin(), end(), [&iter](dvector& v) {
116  v -= *iter;
117  ++iter;
118  });
119 #endif
120  return *this;
121 }
int index_min
Definition: fvar.hpp:2822
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat.cpp:11
void ** m
Definition: dmat.cpp:13
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
exitptr ad_exit
Definition: gradstrc.cpp:53
int index_max
Definition: fvar.hpp:2823
mat_shapex * shape
Definition: fvar.hpp:2825
dmatrix & operator=(const dmatrix &t)
Assign values in other to dmatrix.
Definition: dmat4.cpp:27
int rowmax() const
Definition: fvar.hpp:2929
dvector * begin() const
Definition: fvar.hpp:2900
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dvector * m
Definition: fvar.hpp:2824
int colmin(void) const
Definition: fvar.hpp:2939
dmatrix & operator-=(const dmatrix &t)
Substract element-wise matrix values other from dmatrix.
Definition: dmat4.cpp:100
Description not yet available.
Definition: fvar.hpp:2819
dvector & elem(int i)
Definition: fvar.hpp:3011
unsigned int ncopies
Definition: fvar.hpp:2034
dvector * end() const
Definition: fvar.hpp:2904
dmatrix & operator+=(const dmatrix &t)
Add element-wise matrix values other to dmatrix.
Definition: dmat4.cpp:73
int rowmin() const
Definition: fvar.hpp:2925
int colmax(void) const
Definition: fvar.hpp:2943