resize.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_RESIZE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_RESIZE_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 namespace math {
9 namespace {
10 template <typename T, int R, int C>
11 void resize(Eigen::Matrix<T, R, C>& x, const std::vector<int>& dims, int pos) {
12  x.resize(dims[pos], dims[pos + 1]);
13 }
14 
15 template <typename T>
16 void resize(T /*x*/, const std::vector<int>& /*dims*/, int /*pos*/) {
17  // no-op
18 }
19 
20 template <typename T>
21 void resize(std::vector<T>& x, const std::vector<int>& dims, int pos) {
22  x.resize(dims[pos]);
23  ++pos;
24  if (pos >= static_cast<int>(dims.size()))
25  return; // skips lowest loop to scalar
26  for (size_t i = 0; i < x.size(); ++i)
27  resize(x[i], dims, pos);
28 }
29 } // namespace
30 
31 /**
32  * Recursively resize the specified vector of vectors,
33  * which must bottom out at scalar values, Eigen vectors
34  * or Eigen matrices.
35  *
36  * @param x Array-like object to resize.
37  * @param dims New dimensions.
38  * @tparam T Type of object being resized.
39  */
40 template <typename T>
41 inline void resize(T& x, std::vector<int> dims) {
42  resize(x, dims, 0U);
43 }
44 
45 } // namespace math
46 } // namespace stan
47 #endif
void dims(const T &x, std::vector< int > &result)
Definition: dims.hpp:11
void resize(T &x, std::vector< int > dims)
Definition: resize.hpp:41
double T
Definition: Xdiff_gwt.C:5