Automatic Differentiation
 
Loading...
Searching...
No Matches
rep_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_REP_MATRIX_HPP
2#define STAN_MATH_PRIM_FUN_REP_MATRIX_HPP
3
7
8namespace stan {
9namespace math {
10
21template <typename Ret, typename T,
22 require_eigen_matrix_dynamic_vt<is_stan_scalar, Ret>* = nullptr,
23 require_stan_scalar_t<T>* = nullptr>
24inline auto rep_matrix(const T& x, int m, int n) {
25 check_nonnegative("rep_matrix", "rows", m);
26 check_nonnegative("rep_matrix", "cols", n);
27 return Ret::Constant(m, n, x);
28}
29
39template <typename T, require_stan_scalar_t<T>* = nullptr>
40inline auto rep_matrix(const T& x, int m, int n) {
41 return rep_matrix<
42 Eigen::Matrix<return_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>>(x, m, n);
43}
44
53template <typename Vec, require_eigen_vector_t<Vec>* = nullptr>
54inline auto rep_matrix(const Vec& x, int n) {
56 check_nonnegative("rep_matrix", "rows", n);
57 return x.replicate(n, 1);
58 } else {
59 check_nonnegative("rep_matrix", "cols", n);
60 return x.replicate(1, n);
61 }
62}
63
64} // namespace math
65} // namespace stan
66
67#endif
auto rep_matrix(const value_type_t< T > &x, int n, int m)
Creates a matrix_cl by replicating the given value of arithmetic type.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
If the input type T is an eigen matrix with 1 column at compile time this has a static member with a ...