Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
resize.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__RESIZE_HPP__
2 #define __STAN__MATH__MATRIX__RESIZE_HPP__
3 
4 #include <vector>
6 
7 namespace stan {
8  namespace math {
9 
10  namespace {
11 
12  template <typename T>
13  void resize(Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>& x,
14  const std::vector<size_t>& dims,
15  size_t pos) {
16  x.resize(dims[pos],dims[pos+1]);
17  }
18 
19  template <typename T>
20  void resize(Eigen::Matrix<T,Eigen::Dynamic,1>& x,
21  const std::vector<size_t>& dims,
22  size_t pos) {
23  x.resize(dims[pos]);
24  }
25 
26  template <typename T>
27  void resize(Eigen::Matrix<T,1,Eigen::Dynamic>& x,
28  const std::vector<size_t>& dims,
29  size_t pos) {
30  x.resize(dims[pos]);
31  }
32 
33 
34  void resize(double /*x*/,
35  const std::vector<size_t>& /*dims*/,
36  size_t /*pos*/) {
37  // no-op
38  }
39 
40  template <typename T>
41  void resize(std::vector<T>& x,
42  const std::vector<size_t>& dims,
43  size_t pos) {
44  x.resize(dims[pos]);
45  ++pos;
46  if (pos >= dims.size()) return; // skips lowest loop to scalar
47  for (size_t i = 0; i < x.size(); ++i)
48  resize(x[i],dims,pos);
49  }
50 
51  }
52 
62  template <typename T>
63  inline void resize(T& x, std::vector<size_t> dims) {
64  resize(x,dims,0U);
65  }
66 
67  }
68 }
69 #endif

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