| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

container_view.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_META_CONTAINER_VIEW_HPP
2 #define STAN_MATH_PRIM_MAT_META_CONTAINER_VIEW_HPP
3
4 #include <stan/math/prim/scal/meta/container_view.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <vector>
7
8 namespace stan {
9 namespace math {
10
21 template <typename T1, typename T2, int R, int C>
22 class container_view<Eigen::Matrix<T1, R, C>, Eigen::Matrix<T2, R, C> > {
23 public:
31 container_view(const Eigen::Matrix<T1, R, C>& x, T2* y)
32 : y_(y, x.rows(), x.cols()) { }
33
39 Eigen::Map<Eigen::Matrix<T2, R, C> >& operator[](int i) {
40 return y_;
41 }
42 private:
43 Eigen::Map<Eigen::Matrix<T2, R, C> > y_;
44 };
45
56 template <typename T1, typename T2, int R, int C>
57 class container_view<Eigen::Matrix<T1, R, C>, T2> {
58 public:
65 container_view(const Eigen::Matrix<T1, R, C>& x, T2* y)
66 : y_(y) { }
67
72 T2& operator[](int i) {
73 return y_[i];
74 }
75 private:
76 T2* y_;
77 };
78
89 template <typename T1, typename T2, int R, int C>
90 class container_view<std::vector<Eigen::Matrix<T1, R, C> >,
91 Eigen::Matrix<T2, R, C> > {
92 public:
103 container_view(const std::vector<Eigen::Matrix<T1, R, C> >& x, T2* y)
104 : y_view(y, 1, 1), y_(y) {
105 if (x.size() > 0) {
106 rows = x[0].rows();
107 cols = x[0].cols();
108 } else {
109 rows = 0;
110 cols = 0;
111 }
112 }
113
118 Eigen::Map<Eigen::Matrix<T2, R, C> >& operator[](int i) {
119 int offset = i * rows * cols;
120 new (&y_view) Eigen::Map<Eigen::Matrix<T2, R, C> >
121 (y_ + offset, rows, cols);
122 return y_view;
123 }
124 private:
125 Eigen::Map<Eigen::Matrix<T2, R, C> > y_view;
126 T2* y_;
127 int rows;
128 int cols;
129 };
130 }
131 }
132 #endif
stan::math::rows
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
Definition: rows.hpp:20
stan
Definition: log_sum_exp.hpp:8
stan::math::container_view< std::vector< Eigen::Matrix< T1, R, C > >, Eigen::Matrix< T2, R, C > >::operator[]
Eigen::Map< Eigen::Matrix< T2, R, C > > & operator[](int i)
operator[](int i) returns matrix view of scalartype T2 at appropriate index i in array y ...
Definition: container_view.hpp:118
std
Definition: std_numeric_limits.hpp:7
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:9
stan::math::container_view< Eigen::Matrix< T1, R, C >, T2 >::container_view
container_view(const Eigen::Matrix< T1, R, C > &x, T2 *y)
Constructor.
Definition: container_view.hpp:65
stan::math::container_view< Eigen::Matrix< T1, R, C >, Eigen::Matrix< T2, R, C > >::operator[]
Eigen::Map< Eigen::Matrix< T2, R, C > > & operator[](int i)
operator[](int i) returns Eigen::Map y
Definition: container_view.hpp:39
stan::math::cols
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
Definition: cols.hpp:20
Eigen.hpp
stan::math::container_view< Eigen::Matrix< T1, R, C >, T2 >::operator[]
T2 & operator[](int i)
operator[](int i) returns reference to scalar of type T2 at appropriate index i in array y ...
Definition: container_view.hpp:72
stan::math::container_view
Primary template class for container view of array y with same structure as T1 and size as x...
Definition: container_view.hpp:19
container_view.hpp
stan::math::container_view< Eigen::Matrix< T1, R, C >, Eigen::Matrix< T2, R, C > >::container_view
container_view(const Eigen::Matrix< T1, R, C > &x, T2 *y)
Initialize Map dimensions with input matrix dimensions.
Definition: container_view.hpp:31
stan::math::container_view< std::vector< Eigen::Matrix< T1, R, C > >, Eigen::Matrix< T2, R, C > >::container_view
container_view(const std::vector< Eigen::Matrix< T1, R, C > > &x, T2 *y)
Constructor assumes all matrix elements in std::vector are of same dimension.
Definition: container_view.hpp:103

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