| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

append_col.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_APPEND_COL_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_APPEND_COL_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
36 template <typename T1, typename T2, int R1, int C1, int R2, int C2>
37 inline Eigen::Matrix<typename return_type<T1, T2>::type,
38 Eigen::Dynamic, Eigen::Dynamic>
39 append_col(const Eigen::Matrix<T1, R1, C1>& A,
40 const Eigen::Matrix<T2, R2, C2>& B) {
41 using Eigen::Dynamic;
42 using Eigen::Matrix;
43 using stan::math::check_size_match;
44
45 int Arows = A.rows();
46 int Brows = B.rows();
47 int Acols = A.cols();
48 int Bcols = B.cols();
49 check_size_match("append_col",
50 "rows of A", Arows,
51 "rows of B", Brows);
52
53 Matrix<typename return_type<T1, T2>::type, Dynamic, Dynamic>
54 result(Arows, Acols+Bcols);
55 for (int j = 0; j < Acols; j++)
56 for (int i = 0; i < Arows; i++)
57 result(i, j) = A(i, j);
58
59 for (int j = Acols, k = 0; k < Bcols; j++, k++)
60 for (int i = 0; i < Arows; i++)
61 result(i, j) = B(i, k);
62 return result;
63 }
64
82 template <typename T1, typename T2, int C1, int C2>
83 inline Eigen::Matrix<typename return_type<T1, T2>::type,
84 1, Eigen::Dynamic>
85 append_col(const Eigen::Matrix<T1, 1, C1>& A,
86 const Eigen::Matrix<T2, 1, C2>& B) {
87 using Eigen::Dynamic;
88 using Eigen::Matrix;
89
90 int Asize = A.size();
91 int Bsize = B.size();
92 Matrix<typename return_type<T1, T2>::type, 1, Dynamic>
93 result(Asize + Bsize);
94 for (int i = 0; i < Asize; i++)
95 result(i) = A(i);
96 for (int i = 0, j = Asize; i < Bsize; i++, j++)
97 result(j) = B(i);
98 return result;
99 }
100
101
126 template <typename T, int R1, int C1, int R2, int C2>
127 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
128 append_col(const Eigen::Matrix<T, R1, C1>& A,
129 const Eigen::Matrix<T, R2, C2>& B) {
130 using Eigen::Matrix;
131 using Eigen::Dynamic;
132
133 check_size_match("append_col",
134 "rows of A", A.rows(),
135 "rows of B", B.rows());
136
137 Matrix<T, Dynamic, Dynamic> result(A.rows(), A.cols()+B.cols());
138 result << A, B;
139 return result;
140 }
141
158 template <typename T, int C1, int C2>
159 inline Eigen::Matrix<T, 1, Eigen::Dynamic>
160 append_col(const Eigen::Matrix<T, 1, C1>& A,
161 const Eigen::Matrix<T, 1, C2>& B) {
162 using Eigen::Matrix;
163 using Eigen::Dynamic;
164
165 Matrix<T, 1, Dynamic> result(A.size()+B.size());
166 result << A, B;
167 return result;
168 }
169
170
185 template <typename T1, typename T2, int R, int C>
186 inline Eigen::Matrix<typename return_type<T1, T2>::type,
187 1, Eigen::Dynamic>
188 append_col(const T1& A,
189 const Eigen::Matrix<T2, R, C>& B) {
190 using Eigen::Dynamic;
191 using Eigen::Matrix;
192 typedef typename return_type<T1, T2>::type return_type;
193
194 Matrix<return_type, 1, Dynamic>
195 result(B.size() + 1);
196 result << A, B.template cast<return_type>();
197 return result;
198 }
199
200
215 template <typename T1, typename T2, int R, int C>
216 inline Eigen::Matrix<typename return_type<T1, T2>::type,
217 1, Eigen::Dynamic>
218 append_col(const Eigen::Matrix<T1, R, C>& A,
219 const T2& B) {
220 using Eigen::Dynamic;
221 using Eigen::Matrix;
222 typedef typename return_type<T1, T2>::type return_type;
223
224 Matrix<return_type, 1, Dynamic>
225 result(A.size() + 1);
226 result << A.template cast<return_type>(), B;
227 return result;
228 }
229 }
230
231 }
232
233 #endif
check_size_match.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::append_col
Eigen::Matrix< typename return_type< T1, T2 >::type, Eigen::Dynamic, Eigen::Dynamic > append_col(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &B)
Return the result of appending the second argument matrix after the first argument matrix...
Definition: append_col.hpp:39
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::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.