Stan Math Library: stan/math/prim/mat/fun/resize.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #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 template <typename T>
34 void resize(T /*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
Definition: log_sum_exp.hpp:8
stan::math::resize
void resize(T &x, std::vector< size_t > dims)
Recursively resize the specified vector of vectors, which must bottom out at scalar values...
Definition: resize.hpp:63
stan::math::dims
void dims(const T &x, std::vector< int > &result)
Definition: dims.hpp:13
Eigen.hpp

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