ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dvect12.cpp
Go to the documentation of this file.
1 
6 #include <fvar.hpp>
7 
12 double sum(const dvector& values)
13 {
14  double total = 0.0;
15  int min = values.indexmin();
16  int max = values.indexmax();
17  double* pvalues = values.get_v() + min;
18  for (int i = min; i <= max; ++i)
19  {
20  total += *pvalues;
21 
22  ++pvalues;
23  }
24  return total;
25 }
32 dvector colsum(const dmatrix& matrix)
33 {
34  int cmin = matrix.colmin();
35  int cmax = matrix.colmax();
36  int rmin = matrix.rowmin();
37  int rmax = matrix.rowmax();
38 
39  dvector sums(cmin, cmax);
40  sums.initialize();
41  double* psumsj = sums.get_v() + cmin;
42  for (int j=cmin; j<=cmax; ++j)
43  {
44  const dvector* pmatrixi = &matrix(rmin);
45  for (int i=rmin; i<=rmax; ++i)
46  {
47  *psumsj += *(pmatrixi->get_v() + j);
48 
49  ++pmatrixi;
50  }
51  ++psumsj;
52  }
53  return sums;
54 }
61 dvector rowsum(const dmatrix& matrix)
62 {
63  int min = matrix.rowmin();
64  int max = matrix.rowmax();
65 
66  dvector sums(min, max);
67  double* psumsi = sums.get_v() + min;
68  const dvector* pmatrixi = &matrix(min);
69  for (int i = min; i <= max; ++i)
70  {
71  *psumsi = sum(*pmatrixi);
72 
73  ++psumsi;
74  ++pmatrixi;
75  }
76  return sums;
77 }
83 double sum(const dmatrix& matrix)
84 {
85  double total = 0.0;
86  int min = matrix.rowmin();
87  int max = matrix.rowmax();
88 
89  const dvector* pmatrixi = &matrix.elem(min);
90  for (int i = min; i <= max; ++i)
91  {
92  total += sum(*pmatrixi);
93 
94  ++pmatrixi;
95  }
96  return total;
97 }
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
int rowmax() const
Definition: fvar.hpp:2929
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 indexmax() const
Get maximum valid index.
Definition: dvector.h:204
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
int colmin(void) const
Definition: fvar.hpp:2939
Description not yet available.
Definition: fvar.hpp:2819
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
dvector & elem(int i)
Definition: fvar.hpp:3011
values
Definition: adjson.h:22
#define max(a, b)
Definition: cbivnorm.cpp:189
double *& get_v(void)
Definition: dvector.h:148
int rowmin() const
Definition: fvar.hpp:2925
int colmax(void) const
Definition: fvar.hpp:2943