Stan Math Library  2.6.3
probability, sampling & optimization
 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 
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;
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
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
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.

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