Stan Math Library: stan/math/prim/mat/meta/VectorViewMvt.hpp Source File

| Stan Math Library 2.10.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 template <typename T, bool is_array
13 = stan::is_vector_like
14 <typename stan::math::value_type<T>::type>::value,
15 bool throw_if_accessed = false>
16 class VectorViewMvt {
17 public:
18 typedef typename scalar_type_pre<T>::type matrix_t;
19
20 explicit VectorViewMvt(matrix_t& m) : x_(&m) { }
21
22 explicit VectorViewMvt(std::vector<matrix_t>& vm) : x_(&vm[0]) { }
23
24 matrix_t& operator[](int i) {
25 if (throw_if_accessed)
26 throw std::out_of_range("VectorViewMvt: this cannot be accessed");
27 if (is_array)
28 return x_[i];
29 else
30 return x_[0];
31 }
32 private:
33 matrix_t* x_;
34 };
35
40 template <typename T, bool is_array, bool throw_if_accessed>
41 class VectorViewMvt<const T, is_array, throw_if_accessed> {
42 public:
43 typedef typename scalar_type_pre<T>::type matrix_t;
44
45 explicit VectorViewMvt(const matrix_t& m) : x_(&m) { }
46
47 explicit VectorViewMvt(const std::vector<matrix_t>& vm) : x_(&vm[0]) { }
48
49 const matrix_t& operator[](int i) const {
50 if (throw_if_accessed)
51 throw std::out_of_range("VectorViewMvt: this cannot be accessed");
52 if (is_array)
53 return x_[i];
54 else
55 return x_[0];
56 }
57 private:
58 const matrix_t* x_;
59 };
60
61
62 }
63 #endif
64
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:39
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)
Definition: VectorViewMvt.hpp:22
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const std::vector< matrix_t > &vm)
Definition: VectorViewMvt.hpp:47
stan::VectorViewMvt::operator[]
matrix_t & operator[](int i)
Definition: VectorViewMvt.hpp:24
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:30
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::operator[]
const matrix_t & operator[](int i) const
Definition: VectorViewMvt.hpp:49
stan::VectorViewMvt::VectorViewMvt
VectorViewMvt(matrix_t &m)
Definition: VectorViewMvt.hpp:20
stan::VectorViewMvt
Definition: VectorViewMvt.hpp:16
stan::VectorViewMvt::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:18
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const matrix_t &m)
Definition: VectorViewMvt.hpp:45
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:43
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.