Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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 
10  namespace math {
11 
12  template <typename T>
13  inline
14  Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
15  Eigen::Dynamic, Eigen::Dynamic>
16  rep_matrix(const T& x, int m, int n) {
18  check_nonnegative("rep_matrix", "rows", m);
19  check_nonnegative("rep_matrix", "cols", n);
20  return Eigen::Matrix<typename boost::math::tools::promote_args<T>::type,
21  Eigen::Dynamic, Eigen::Dynamic>::Constant(m, n, x);
22  }
23 
24  template <typename T>
25  inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
26  rep_matrix(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v, int n) {
28  check_nonnegative("rep_matrix", "rows", n);
29  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(v.size(), n);
30  result.colwise() = v;
31  return result;
32  }
33 
34  template <typename T>
35  inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
36  rep_matrix(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv, int m) {
38  check_nonnegative("rep_matrix", "cols", m);
39  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(m, rv.size());
40  result.rowwise() = rv;
41  return result;
42  }
43  }
44 }
45 
46 #endif
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true 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:16

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