| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

append_row.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_APPEND_ROW_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_APPEND_ROW_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/scal/meta/return_type.hpp>
6 #include <stan/math/prim/scal/err/check_size_match.hpp>
7 #include <vector>
8
9 namespace stan {
10 namespace math {
11
33 template <typename T1, typename T2, int R1, int C1, int R2, int C2>
34 inline Eigen::Matrix<typename return_type<T1, T2>::type,
35 Eigen::Dynamic, Eigen::Dynamic>
36 append_row(const Eigen::Matrix<T1, R1, C1>& A,
37 const Eigen::Matrix<T2, R2, C2>& B) {
38 using Eigen::Dynamic;
39 using Eigen::Matrix;
40
41 int Arows = A.rows();
42 int Brows = B.rows();
43 int Acols = A.cols();
44 int Bcols = B.cols();
45 check_size_match("append_row",
46 "columns of A", Acols,
47 "columns of B", Bcols);
48
49 Matrix<typename return_type<T1, T2>::type, Dynamic, Dynamic>
50 result(Arows + Brows, Acols);
51 for (int j = 0; j < Acols; j++) {
52 for (int i = 0; i < Arows; i++)
53 result(i, j) = A(i, j);
54 for (int i = Arows, k = 0; k < Brows; i++, k++)
55 result(i, j) = B(k, j);
56 }
57 return result;
58 }
59
75 template <typename T1, typename T2, int R1, int R2>
76 inline Eigen::Matrix<typename return_type<T1, T2>::type,
77 Eigen::Dynamic, 1>
78 append_row(const Eigen::Matrix<T1, R1, 1>& A,
79 const Eigen::Matrix<T2, R2, 1>& B) {
80 using Eigen::Dynamic;
81 using Eigen::Matrix;
82
83 int Asize = A.size();
84 int Bsize = B.size();
85 Matrix<typename return_type<T1, T2>::type, 1, Dynamic>
86 result(Asize + Bsize);
87 for (int i = 0; i < Asize; i++)
88 result(i) = A(i);
89 for (int i = 0, j = Asize; i < Bsize; i++, j++)
90 result(j) = B(i);
91 return result;
92 }
93
116 template <typename T, int R1, int C1, int R2, int C2>
117 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
118 append_row(const Eigen::Matrix<T, R1, C1>& A,
119 const Eigen::Matrix<T, R2, C2>& B) {
120 using Eigen::Dynamic;
121 using Eigen::Matrix;
122
123 check_size_match("append_row",
124 "columns of A", A.cols(),
125 "columns of B", B.cols());
126
127 Matrix<T, Dynamic, Dynamic>
128 result(A.rows() + B.rows(), A.cols());
129 result << A, B;
130 return result;
131 }
132
149 template <typename T, int R1, int R2>
150 inline Eigen::Matrix<T, Eigen::Dynamic, 1>
151 append_row(const Eigen::Matrix<T, R1, 1>& A,
152 const Eigen::Matrix<T, R2, 1>& B) {
153 using Eigen::Dynamic;
154 using Eigen::Matrix;
155
156 Matrix<T, Dynamic, 1> result(A.size()+B.size());
157 result << A, B;
158 return result;
159 }
160
174 template <typename T1, typename T2, int R, int C>
175 inline Eigen::Matrix<typename return_type<T1, T2>::type,
176 Eigen::Dynamic, 1>
177 append_row(const T1& A,
178 const Eigen::Matrix<T2, R, C>& B) {
179 using Eigen::Dynamic;
180 using Eigen::Matrix;
181 typedef typename return_type<T1, T2>::type return_type;
182
183 Matrix<return_type, Dynamic, 1>
184 result(B.size() + 1);
185 result << A, B.template cast<return_type>();
186 return result;
187 }
188
202 template <typename T1, typename T2, int R, int C>
203 inline Eigen::Matrix<typename return_type<T1, T2>::type,
204 Eigen::Dynamic, 1>
205 append_row(const Eigen::Matrix<T1, R, C>& A,
206 const T2& B) {
207 using Eigen::Dynamic;
208 using Eigen::Matrix;
209 typedef typename return_type<T1, T2>::type return_type;
210
211 Matrix<return_type, Dynamic, 1>
212 result(A.size() + 1);
213 result << A.template cast<return_type>(), B;
214 return result;
215 }
216
217 }
218
219 }
220
221 #endif
check_size_match.hpp
stan
Definition: log_sum_exp.hpp:8
stan::return_type
Metaprogram to calculate the base scalar return type resulting from promoting all the scalar types of...
Definition: return_type.hpp:19
return_type.hpp
stan::return_type::type
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type
Definition: return_type.hpp:27
stan::math::append_row
Eigen::Matrix< typename return_type< T1, T2 >::type, Eigen::Dynamic, Eigen::Dynamic > append_row(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &B)
Return the result of stacking the rows of the first argument matrix on top of the second argument mat...
Definition: append_row.hpp:36
stan::math::check_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
Eigen.hpp

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