| Stan Math Library 2.11.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
10 namespace math {
11
22 template <typename T1, typename T2, int R, int C>
23 class container_view<Eigen::Matrix<T1, R, C>, Eigen::Matrix<T2, R, C> > {
24 public:
32 container_view(const Eigen::Matrix<T1, R, C>& x, T2* y)
33 : y_(y, x.rows(), x.cols()) { }
34
40 Eigen::Map<Eigen::Matrix<T2, R, C> >& operator[](int i) {
41 return y_;
42 }
43 private:
44 Eigen::Map<Eigen::Matrix<T2, R, C> > y_;
45 };
46
57 template <typename T1, typename T2, int R, int C>
58 class container_view<Eigen::Matrix<T1, R, C>, T2> {
59 public:
66 container_view(const Eigen::Matrix<T1, R, C>& x, T2* y)
67 : y_(y) { }
68
73 T2& operator[](int i) {
74 return y_[i];
75 }
76 private:
77 T2* y_;
78 };
79
90 template <typename T1, typename T2, int R, int C>
91 class container_view<std::vector<Eigen::Matrix<T1, R, C> >,
92 Eigen::Matrix<T2, R, C> > {
93 public:
104 container_view(const std::vector<Eigen::Matrix<T1, R, C> >& x, T2* y)
105 : y_view(y, 1, 1), y_(y) {
106 if (x.size() > 0) {
107 rows = x[0].rows();
108 cols = x[0].cols();
109 } else {
110 rows = 0;
111 cols = 0;
112 }
113 }
114
119 Eigen::Map<Eigen::Matrix<T2, R, C> >& operator[](int i) {
120 int offset = i * rows * cols;
121 new (&y_view) Eigen::Map<Eigen::Matrix<T2, R, C> >
122 (y_ + offset, rows, cols);
123 return y_view;
124 }
125 private:
126 Eigen::Map<Eigen::Matrix<T2, R, C> > y_view;
127 T2* y_;
128 int rows;
129 int cols;
130 };
131 }
132 }
133 #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:119
std
Definition: std_numeric_limits.hpp:7
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:8
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:66
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:40
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:73
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:22
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:32
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:104

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