Stan Math Library  2.20.0
reverse mode automatic differentiation
positive_ordered_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_POSITIVE_ORDERED_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_POSITIVE_ORDERED_CONSTRAIN_HPP
3 
6 #include <cmath>
7 
8 namespace stan {
9 namespace math {
10 
20 template <typename T>
21 Eigen::Matrix<T, Eigen::Dynamic, 1> positive_ordered_constrain(
22  const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
23  using Eigen::Dynamic;
24  using Eigen::Matrix;
25  using std::exp;
26  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
27 
28  size_type k = x.size();
29  Matrix<T, Dynamic, 1> y(k);
30  if (k == 0)
31  return y;
32  y[0] = exp(x[0]);
33  for (size_type i = 1; i < k; ++i)
34  y[i] = y[i - 1] + exp(x[i]);
35  return y;
36 }
37 
50 template <typename T>
51 inline Eigen::Matrix<T, Eigen::Dynamic, 1> positive_ordered_constrain(
52  const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& lp) {
53  using Eigen::Dynamic;
54  using Eigen::Matrix;
55  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
56 
57  for (size_type i = 0; i < x.size(); ++i)
58  lp += x(i);
60 }
61 
62 } // namespace math
63 
64 } // namespace stan
65 
66 #endif
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:11
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing positive ordered vector derived from the specified free vector.
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11

     [ Stan Home Page ] © 2011–2018, Stan Development Team.