ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imat8.cpp
Go to the documentation of this file.
1 /*
2 Author: David Fournier
3 Copyright (c) 2008-2012 Regents of the University of California
4 */
5 
6 #include <fvar.hpp>
7 
14 ivector colsum(const imatrix& matrix)
15 {
16  int jmin = matrix.colmin();
17  int jmax = matrix.colmax();
18  ivector colsums(jmin, jmax);
19 
20  int imin = matrix.rowmin();
21  int imax = matrix.rowmax();
22 
23  int* pcolumnsj = colsums.get_v() + jmin;
24  for (int j = jmin; j <= jmax; ++j)
25  {
26  *pcolumnsj = 0;
27 
28  const ivector* pmatrixi = &matrix(imin);
29  for (int i = imin; i <= imax; ++i)
30  {
31  *pcolumnsj += *(pmatrixi->get_v() + j);
32 
33  ++pmatrixi;
34  }
35 
36  ++pcolumnsj;
37  }
38  return colsums;
39 }
46 ivector rowsum(const imatrix& matrix)
47 {
48  int min = matrix.rowmin();
49  int max = matrix.rowmax();
50  ivector rowsums(min, max);
51 
52  int* prowsumsi = rowsums.get_v() + min;
53  const ivector* pmatrixi = &matrix(min);
54  for (int i = min; i <= max; ++i)
55  {
56  *prowsumsi = sum(*pmatrixi);
57  ++pmatrixi;
58  ++prowsumsi;
59  }
60 
61  return rowsums;
62 }
69 void imatrix::fill_seqadd(int start, int increment)
70 {
71  int current = start;
72 
73  int imin = indexmin();
74  int imax = indexmax();
75  for (int i = imin; i <= imax; ++i)
76  {
77  if (allocated(elem(i)))
78  {
79  elem(i).fill_seqadd(current, increment);
80  current = elem(i, elem(i).indexmax()) + increment;
81  }
82  }
83 }
ivector & elem(int i)
Definition: imatrix.h:233
int indexmax() const
Definition: imatrix.h:142
Description not yet available.
Definition: imatrix.h:69
int indexmin() const
Definition: imatrix.h:138
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
int rowmin() const
Definition: imatrix.h:146
void fill_seqadd(int, int)
Fills ivector elements with values starting from base and incremented by offset.
Definition: cranfill.cpp:73
int * get_v() const
Definition: ivector.h:114
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
dvector rowsum(const dmatrix &matrix)
Returns dvector where each element contains the sum total of each row in matrix.
Definition: dvect12.cpp:61
#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.
double colsum(const dmatrix &m, int col)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat27.cpp:10
void fill_seqadd(int, int)
Fill imatrix with sequence of integers from start and adding with increment.
Definition: imat8.cpp:69
int colmax(void) const
Definition: imatrix.h:159
#define max(a, b)
Definition: cbivnorm.cpp:189
int rowmax() const
Definition: imatrix.h:150