| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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
11 namespace math {
12
34 template <typename T1, typename T2, int R1, int C1, int R2, int C2>
35 inline Eigen::Matrix<typename return_type<T1, T2>::type,
36 Eigen::Dynamic, Eigen::Dynamic>
37 append_row(const Eigen::Matrix<T1, R1, C1>& A,
38 const Eigen::Matrix<T2, R2, C2>& B) {
39 using Eigen::Dynamic;
40 using Eigen::Matrix;
41
42 int Arows = A.rows();
43 int Brows = B.rows();
44 int Acols = A.cols();
45 int Bcols = B.cols();
46 check_size_match("append_row",
47 "columns of A", Acols,
48 "columns of B", Bcols);
49
50 Matrix<typename return_type<T1, T2>::type, Dynamic, Dynamic>
51 result(Arows + Brows, Acols);
52 for (int j = 0; j < Acols; j++) {
53 for (int i = 0; i < Arows; i++)
54 result(i, j) = A(i, j);
55 for (int i = Arows, k = 0; k < Brows; i++, k++)
56 result(i, j) = B(k, j);
57 }
58 return result;
59 }
60
61
77 template <typename T1, typename T2, int R1, int R2>
78 inline Eigen::Matrix<typename return_type<T1, T2>::type,
79 Eigen::Dynamic, 1>
80 append_row(const Eigen::Matrix<T1, R1, 1>& A,
81 const Eigen::Matrix<T2, R2, 1>& B) {
82 using Eigen::Dynamic;
83 using Eigen::Matrix;
84
85 int Asize = A.size();
86 int Bsize = B.size();
87 Matrix<typename return_type<T1, T2>::type, 1, Dynamic>
88 result(Asize + Bsize);
89 for (int i = 0; i < Asize; i++)
90 result(i) = A(i);
91 for (int i = 0, j = Asize; i < Bsize; i++, j++)
92 result(j) = B(i);
93 return result;
94 }
95
96
119 template <typename T, int R1, int C1, int R2, int C2>
120 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
121 append_row(const Eigen::Matrix<T, R1, C1>& A,
122 const Eigen::Matrix<T, R2, C2>& B) {
123 using Eigen::Dynamic;
124 using Eigen::Matrix;
125
126 check_size_match("append_row",
127 "columns of A", A.cols(),
128 "columns of B", B.cols());
129
130 Matrix<T, Dynamic, Dynamic>
131 result(A.rows() + B.rows(), A.cols());
132 result << A, B;
133 return result;
134 }
135
136
153 template <typename T, int R1, int R2>
154 inline Eigen::Matrix<T, Eigen::Dynamic, 1>
155 append_row(const Eigen::Matrix<T, R1, 1>& A,
156 const Eigen::Matrix<T, R2, 1>& B) {
157 using Eigen::Dynamic;
158 using Eigen::Matrix;
159
160 Matrix<T, Dynamic, 1> result(A.size()+B.size());
161 result << A, B;
162 return result;
163 }
164
165 }
166
167 }
168
169 #endif
check_size_match.hpp
return_type.hpp
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:37
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–2015, Stan Development Team.