TMB Documentation  v1.9.11
tmbutils/vectorize.hpp
Go to the documentation of this file.
1 #ifdef TMBAD_FRAMEWORK
2 
22 namespace vectorize {
23 
25 template <class Type>
27  typedef TMBad::ad_segment Base;
28  using Base::Base;
29  vector() {} // Surprisingly, needed on some systems.
31  Base(x.data(), x.size()) { }
32  vector(const Base &x) :
33  Base(x) { }
34  operator std::vector<Type>() const {
35  std::vector<Type> x(this->size());
36  for (size_t i=0; i<this->size(); i++)
37  x[i] = (*this)[i];
38  return x;
39  }
40  operator tmbutils::vector<Type>() const {
41  tmbutils::vector<Type> x(this->size());
42  for (size_t i=0; i<this->size(); i++)
43  x[i] = (*this)[i];
44  return x;
45  }
47  return *this;
48  }
49  Type sum() const {
50  return TMBad::sum(*this);
51  }
52 };
53 template <>
54 struct vector<double> : tmbutils::vector<double> {
56  using Base::Base;
57  vector() {} // Surprisingly, needed on some systems.
58  vector(tmbutils::vector<double> x) : Base(x) { }
59 };
60 
62 template<class Type, class T1, class T2>
63 vector<Type> dnorm(vector<Type> x, T1 mean, T2 sd, int give_log=0)
64 {
65  vector<Type> logres;
66  x = (x - mean) / sd;
67  logres = -log(Type(sqrt(2*M_PI)) * sd) - Type(.5) * x * x;
68  if(give_log) return logres;
69  else return exp(logres);
70 }
71 
72 } // End namespace
73 
74 #endif
Contiguous set of variables on the current tape.
Definition: global.hpp:2780
Vector of consequtive values on the AD tape.
Array class used by TMB.
Definition: array.hpp:22
vector< Type > dnorm(vector< Type > x, T1 mean, T2 sd, int give_log=0)
Demonstrate native vectorization of &#39;dnorm&#39;.
Vectorized atomic functions.
Vector class used by TMB.
Definition: tmbutils.hpp:18
License: GPL v2