Stan Math Library  2.14.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
13  Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
14  Eigen::Dynamic, Eigen::Dynamic>
15  rep_matrix(const T& x, int m, int n) {
16  check_nonnegative("rep_matrix", "rows", m);
17  check_nonnegative("rep_matrix", "cols", n);
18  return Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
19  Eigen::Dynamic, Eigen::Dynamic>::Constant(m, n, x);
20  }
21 
22  template <typename T>
23  inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
24  rep_matrix(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v, int n) {
25  check_nonnegative("rep_matrix", "rows", n);
26  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(v.size(), n);
27  result.colwise() = v;
28  return result;
29  }
30 
31  template <typename T>
32  inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
33  rep_matrix(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv, int m) {
34  check_nonnegative("rep_matrix", "cols", m);
35  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(m, rv.size());
36  result.rowwise() = rv;
37  return result;
38  }
39  }
40 }
41 
42 #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:15

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