Stan Math Library  2.20.0
reverse mode automatic differentiation
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 internal {
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 internal
30 
40 template <typename T>
41 inline void resize(T& x, std::vector<int> dims) {
42  internal::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(Eigen::Matrix< T, R, C > &x, const std::vector< int > &dims, int pos)
Definition: resize.hpp:11

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