Stan Math Library  2.12.0
reverse mode automatic differentiation
VectorViewMvt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_META_VECTORVIEWMVT_HPP
2 #define STAN_MATH_PRIM_MAT_META_VECTORVIEWMVT_HPP
3 
7 #include <stdexcept>
8 #include <vector>
9 
10 namespace stan {
11 
12 
25  template <typename T, bool is_array
27  <typename stan::math::value_type<T>::type>::value,
28  bool throw_if_accessed = false>
29  class VectorViewMvt {
30  public:
32 
36  explicit VectorViewMvt(matrix_t& m) : x_(&m) { }
37 
41  explicit VectorViewMvt(std::vector<matrix_t>& vm) : x_(&vm[0]) { }
42 
54  matrix_t& operator[](int i) {
55  if (throw_if_accessed)
56  throw std::out_of_range("VectorViewMvt: this cannot be accessed");
57  if (is_array)
58  return x_[i];
59  else
60  return x_[0];
61  }
62 
63  private:
64  matrix_t* x_;
65  };
66 
71  template <typename T, bool is_array, bool throw_if_accessed>
72  class VectorViewMvt<const T, is_array, throw_if_accessed> {
73  public:
75 
76  explicit VectorViewMvt(const matrix_t& m) : x_(&m) { }
77 
78  explicit VectorViewMvt(const std::vector<matrix_t>& vm) : x_(&vm[0]) { }
79 
91  const matrix_t& operator[](int i) const {
92  if (throw_if_accessed)
93  throw std::out_of_range("VectorViewMvt: this cannot be accessed");
94  if (is_array)
95  return x_[i];
96  else
97  return x_[0];
98  }
99 
100  private:
101  const matrix_t* x_;
102  };
103 
104 }
105 #endif
106 
scalar_type_helper_pre< is_vector< typename stan::math::value_type< T >::type >::value, typename stan::math::value_type< T >::type, T >::type type
Template metaprogram indicates whether a type is vector_like.
VectorViewMvt(std::vector< matrix_t > &vm)
Constructor.
matrix_t & operator[](int i)
Allows the structure to be accessed like an array.
void out_of_range(const char *function, const int max, const int index, const char *msg1="", const char *msg2="")
Throw an out_of_range exception with a consistently formatted message.
const matrix_t & operator[](int i) const
Allows the structure to be accessed like an array.
VectorViewMvt(matrix_t &m)
Constructor.
VectorViewMvt is a template expression that wraps either an Eigen::Matrix or a std::vector
scalar_type_pre< T >::type matrix_t
Primary template class for metaprogram to compute the type of values stored in a container.
Definition: value_type.hpp:18

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