| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/meta/is_vector_like.hpp>
5 #include <stan/math/prim/scal/meta/is_vector_like.hpp>
6 #include <stan/math/prim/scal/meta/scalar_type_pre.hpp>
7 #include <stdexcept>
8 #include <vector>
9
10 namespace stan {
11
12
25 template <typename T, bool is_array
26 = stan::is_vector_like
27 <typename stan::math::value_type<T>::type>::value,
28 bool throw_if_accessed = false>
29 class VectorViewMvt {
30 public:
31 typedef typename scalar_type_pre<T>::type matrix_t;
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:
74 typedef typename scalar_type_pre<T>::type matrix_t;
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
stan::scalar_type_pre::type
scalar_type_helper_pre< is_vector< typename stan::math::value_type< T >::type >::value, typename stan::math::value_type< T >::type, T >::type type
Definition: scalar_type_pre.hpp:38
stan::is_vector_like
Template metaprogram indicates whether a type is vector_like.
Definition: is_vector_like.hpp:21
stan
Definition: log_sum_exp.hpp:8
is_vector_like.hpp
stan::VectorViewMvt::VectorViewMvt
VectorViewMvt(std::vector< matrix_t > &vm)
Constructor.
Definition: VectorViewMvt.hpp:41
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const std::vector< matrix_t > &vm)
Definition: VectorViewMvt.hpp:78
stan::VectorViewMvt::operator[]
matrix_t & operator[](int i)
Allows the structure to be accessed like an array.
Definition: VectorViewMvt.hpp:54
is_vector_like.hpp
scalar_type_pre.hpp
stan::math::out_of_range
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.
Definition: out_of_range.hpp:31
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::operator[]
const matrix_t & operator[](int i) const
Allows the structure to be accessed like an array.
Definition: VectorViewMvt.hpp:91
stan::VectorViewMvt::VectorViewMvt
VectorViewMvt(matrix_t &m)
Constructor.
Definition: VectorViewMvt.hpp:36
stan::VectorViewMvt
VectorViewMvt is a template expression that wraps either an Eigen::Matrix or a std::vector
Definition: VectorViewMvt.hpp:29
stan::VectorViewMvt::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:31
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const matrix_t &m)
Definition: VectorViewMvt.hpp:76
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:74
stan::math::value_type
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.