1 #ifndef STAN_MATH_PRIM_FUN_INITIALIZE_FILL_HPP
2 #define STAN_MATH_PRIM_FUN_INITIALIZE_FILL_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 #include <vector>
7
8 namespace stan {
9 namespace math {
10
11 /**
12 * Fill the specified container with the specified value.
13 *
14 * The specified matrix is filled by element.
15 *
16 * @tparam EigMat Type inheriting from `EigenBase`
17 * @tparam S Type of value.
18 *
19 * @param x Container.
20 * @param y Value.
21 */
22 template <typename EigMat, typename S, require_eigen_t<EigMat>* = nullptr,
23 require_stan_scalar_t<S>* = nullptr>
initialize_fill(EigMat & x,const S & y)24 inline void initialize_fill(EigMat& x, const S& y) {
25 x.fill(y);
26 }
27
28 /**
29 * Fill the specified container with the specified value.
30 *
31 * This base case simply assigns the value to the container.
32 *
33 * @tparam T Type of reference container.
34 * @tparam S Type of value.
35 * @param x Container.
36 * @param y Value.
37 */
38 template <
39 typename T, typename S,
40 require_t<std::is_assignable<std::decay_t<T>&, std::decay_t<S>>>* = nullptr>
initialize_fill(T & x,S && y)41 inline void initialize_fill(T& x, S&& y) {
42 x = std::forward<S>(y);
43 }
44
45 /**
46 * Fill the specified container with the specified value.
47 *
48 * Each container in the specified standard vector is filled
49 * recursively by calling <code>fill</code>.
50 *
51 * @tparam Vec A standard vector
52 * @tparam S type of value
53 * @param[in] x Container.
54 * @param[in, out] y Value.
55 */
56 template <typename Vec, typename S, require_std_vector_t<Vec>* = nullptr>
initialize_fill(Vec & x,S && y)57 inline void initialize_fill(Vec& x, S&& y) {
58 for (auto& x_val : x) {
59 initialize_fill(x_val, y);
60 }
61 }
62
63 } // namespace math
64 } // namespace stan
65
66 #endif
67