ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lmat.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 #ifdef __TURBOC__
13  #pragma hdrstop
14 #endif
15 
20  lmatrix::lmatrix(int nrl, int nrh, int ncl, int nch)
21  {
22  allocate(nrl,nrh,ncl,nch);
23  }
24 
29  void lmatrix::allocate(int nrl,int nrh,int ncl,int nch)
30  {
31  if ( (shape = new mat_shape(nrl,nrh,ncl,nch))== 0)
32  {
33  cerr << " Error allocating memory in lmatrix contructor\n";
34  ad_exit(21);
35  }
36 
37  size_t rs = rowsize();
38  if ( (m = new lvector [rs]) == 0)
39  {
40  cerr << " Error allocating memory in lmatrix contructor\n";
41  ad_exit(21);
42  }
43 
44  m -= rowmin();
45  for (int i=rowmin(); i<=rowmax(); i++)
46  {
47  m[i].allocate(ncl,nch);
48  }
49  }
50 
55  void lmatrix::allocate(int nrl,int nrh,const ivector& ncl,const ivector& nch)
56  {
57  if ((shape = new mat_shape(nrl,nrh,ncl(ncl.indexmin()),
58  nch(nch.indexmin()) ))== 0)
59  {
60  cerr << " Error allocating memory in lmatrix contructor\n";
61  ad_exit(21);
62  }
63  if (nrl !=ncl.indexmin() || nrh !=ncl.indexmax() ||
64  nrl !=nch.indexmin() || nrh !=nch.indexmax())
65  {
66  cerr << "Incompatible array bounds in "
67  "dmatrix(int nrl,int nrh, const ivector& ncl, const ivector& nch)\n";
68  ad_exit(1);
69  }
70  size_t rs=rowsize();
71  if ( (m = new lvector [rs]) == 0)
72  {
73  cerr << " Error allocating memory in lmatrix contructor\n";
74  ad_exit(21);
75  }
76  m -= rowmin();
77  for (int i=rowmin(); i<=rowmax(); i++)
78  {
79  m[i].allocate(ncl(i),nch(i));
80  }
81  }
82 
87  void lmatrix::allocate(int nrl, int nrh, int ncl, const ivector& nch)
88  {
89  if (nrl !=nch.indexmin() || nrh !=nch.indexmax())
90  {
91  cerr << "Incompatible array bounds in "
92  "lmatrix::allocate(int nrl,int nrh,int ncl, const ivector& nch)\n";
93  ad_exit(1);
94  }
95  if ( (shape = new mat_shape(nrl,nrh,ncl,nch(nch.indexmin())))== 0)
96  {
97  cerr << " Error allocating memory in lmatrix contructor\n";
98  ad_exit(21);
99  }
100  size_t rs=rowsize();
101  if ( (m = new lvector [rs]) == 0)
102  {
103  cerr << " Error allocating memory in lmatrix contructor\n";
104  ad_exit(21);
105  }
106  m -= rowmin();
107  for (int i=rowmin(); i<=rowmax(); i++)
108  {
109  m[i].allocate(ncl,nch(i));
110  }
111  }
112 
118  {
119  if (m2.shape)
120  {
121  shape=m2.shape;
122  (shape->ncopies)++;
123  m = m2.m;
124  }
125  else
126  {
127  shape=NULL;
128  m=NULL;
129  }
130  }
131 
136 lmatrix::lmatrix(int nrl, int nrh, const ivector& ncl, const ivector& nch)
137  {
138  allocate(nrl,nrh,ncl,nch);
139  }
140 
145 lmatrix::lmatrix(int nrl, int nrh, int ncl, const ivector& nch)
146  {
147  allocate(nrl,nrh,ncl,nch);
148  }
153 {
154  shape = NULL;
155  m=NULL;
156 }
161 {
162  deallocate();
163 }
169  {
170  if (shape)
171  {
172  if (shape->ncopies)
173  {
174  (shape->ncopies)--;
175  }
176  else
177  {
178  //int offset = rowmin();
179  m += rowmin();
180  delete [] m;
181  m=NULL;
182  delete shape;
183  shape=NULL;
184  }
185  }
186  else
187  {
188  //cerr << "Warning -- trying to deallocate an unallocated lmatrix"<<endl;
189  }
190  }
~lmatrix()
Destructor.
Definition: lmat.cpp:160
Description not yet available.
Definition: fvar.hpp:656
lmatrix(void)
Default constructor.
Definition: lmat.cpp:152
int rowmax(void) const
Definition: fvar.hpp:7596
exitptr ad_exit
Definition: gradstrc.cpp:53
unsigned int rowsize() const
Definition: fvar.hpp:7601
unsigned int ncopies
Definition: fvar.hpp:2003
Description not yet available.
Definition: fvar.hpp:7500
int rowmin(void) const
Definition: fvar.hpp:7592
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
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
Description not yet available.
Definition: fvar.hpp:2001
mat_shape * shape
Definition: fvar.hpp:7504
lvector * m
Definition: fvar.hpp:7503
void deallocate()
Description not yet available.
Definition: lmat.cpp:168
void allocate(int ncl, int ncu)
Allocate vector of AD_LONG_INT.
Definition: lvector.cpp:156
void allocate(const lmatrix &dm)
Description not yet available.
Definition: lmat6.cpp:19