| 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_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 }
171
172 }
173
174 #endif
check_size_match.hpp
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
return_type.hpp
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.