All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
append_row.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_APPEND_ROW_HPP
#define STAN_MATH_PRIM_MAT_FUN_APPEND_ROW_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/meta/return_type.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T1, typename T2, int R1, int C1, int R2, int C2>
inline 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) {
using Eigen::Dynamic;
using Eigen::Matrix;
int Arows = A.rows();
int Brows = B.rows();
int Acols = A.cols();
int Bcols = B.cols();
check_size_match("append_row",
"columns of A", Acols,
"columns of B", Bcols);
Matrix<typename return_type<T1, T2>::type, Dynamic, Dynamic>
result(Arows + Brows, Acols);
for (int j = 0; j < Acols; j++) {
for (int i = 0; i < Arows; i++)
result(i, j) = A(i, j);
for (int i = Arows, k = 0; k < Brows; i++, k++)
result(i, j) = B(k, j);
}
return result;
}
template <typename T1, typename T2, int R1, int R2>
inline Eigen::Matrix<typename return_type<T1, T2>::type,
Eigen::Dynamic, 1>
append_row(const Eigen::Matrix<T1, R1, 1>& A,
const Eigen::Matrix<T2, R2, 1>& B) {
using Eigen::Dynamic;
using Eigen::Matrix;
int Asize = A.size();
int Bsize = B.size();
Matrix<typename return_type<T1, T2>::type, 1, Dynamic>
result(Asize + Bsize);
for (int i = 0; i < Asize; i++)
result(i) = A(i);
for (int i = 0, j = Asize; i < Bsize; i++, j++)
result(j) = B(i);
return result;
}
template <typename T, int R1, int C1, int R2, int C2>
inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
append_row(const Eigen::Matrix<T, R1, C1>& A,
const Eigen::Matrix<T, R2, C2>& B) {
using Eigen::Dynamic;
using Eigen::Matrix;
check_size_match("append_row",
"columns of A", A.cols(),
"columns of B", B.cols());
Matrix<T, Dynamic, Dynamic>
result(A.rows() + B.rows(), A.cols());
result << A, B;
return result;
}
template <typename T, int R1, int R2>
inline Eigen::Matrix<T, Eigen::Dynamic, 1>
append_row(const Eigen::Matrix<T, R1, 1>& A,
const Eigen::Matrix<T, R2, 1>& B) {
using Eigen::Dynamic;
using Eigen::Matrix;
Matrix<T, Dynamic, 1> result(A.size()+B.size());
result << A, B;
return result;
}
}
}
#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.