Automatic Differentiation
 
Loading...
Searching...
No Matches
rep_array.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_REP_ARRAY_HPP
2#define STAN_MATH_PRIM_FUN_REP_ARRAY_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
11template <typename T_ret, typename In, require_std_vector_t<T_ret>* = nullptr>
12inline std::vector<plain_type_t<In>> rep_array(const In& x, int n) {
13 using T = plain_type_t<In>;
14 check_nonnegative("rep_array", "n", n);
15 return std::vector<T>(n, x);
16}
17template <typename In>
18inline std::vector<plain_type_t<In>> rep_array(const In& x, int n) {
19 return rep_array<std::vector<plain_type_t<In>>>(x, n);
20}
21
22template <typename In>
23inline std::vector<std::vector<plain_type_t<In>>> rep_array(const In& x, int m,
24 int n) {
25 using std::vector;
26 using T = plain_type_t<In>;
27 check_nonnegative("rep_array", "rows", m);
28 check_nonnegative("rep_array", "cols", n);
29 return vector<vector<T>>(m, vector<T>(n, x));
30}
31
32template <typename In>
33inline std::vector<std::vector<std::vector<plain_type_t<In>>>> rep_array(
34 const In& x, int k, int m, int n) {
35 using std::vector;
36 using T = plain_type_t<In>;
37 check_nonnegative("rep_array", "shelfs", k);
38 check_nonnegative("rep_array", "rows", m);
39 check_nonnegative("rep_array", "cols", n);
40 return vector<vector<vector<T>>>(k, vector<vector<T>>(m, vector<T>(n, x)));
41}
42
43} // namespace math
44} // namespace stan
45
46#endif
auto rep_array(const scalar_type_t< T > &x, int n)
Creates a matrix_cl representing an array by replicating the input value.
Definition rep_array.hpp:32
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9