Stan Math Library  2.20.0
reverse mode automatic differentiation
rep_matrix.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_REP_MATRIX_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_REP_MATRIX_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 template <typename T>
12 inline Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
13  Eigen::Dynamic, Eigen::Dynamic>
14 rep_matrix(const T& x, int m, int n) {
15  check_nonnegative("rep_matrix", "rows", m);
16  check_nonnegative("rep_matrix", "cols", n);
17  return Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
18  Eigen::Dynamic, Eigen::Dynamic>::Constant(m, n, x);
19 }
20 
21 template <typename T>
22 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> rep_matrix(
23  const Eigen::Matrix<T, Eigen::Dynamic, 1>& v, int n) {
24  check_nonnegative("rep_matrix", "rows", n);
25  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(v.size(), n);
26  result.colwise() = v;
27  return result;
28 }
29 
30 template <typename T>
31 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> rep_matrix(
32  const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv, int m) {
33  check_nonnegative("rep_matrix", "cols", m);
34  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(m, rv.size());
35  result.rowwise() = rv;
36  return result;
37 }
38 } // namespace math
39 } // namespace stan
40 
41 #endif
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
Eigen::Matrix< typename boost::math::tools::promote_args< T >::type, Eigen::Dynamic, Eigen::Dynamic > rep_matrix(const T &x, int m, int n)
Definition: rep_matrix.hpp:14

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