Automatic Differentiation
 
Loading...
Searching...
No Matches
resize.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_RESIZE_HPP
2#define STAN_MATH_PRIM_FUN_RESIZE_HPP
3
5#include <vector>
6
7namespace stan {
8namespace math {
9namespace internal {
10template <typename T, int R, int C>
11void resize(Eigen::Matrix<T, R, C>& x, const std::vector<int>& dims, int pos) {
12 x.resize(dims[pos], dims[pos + 1]);
13}
14
15template <typename T>
16void resize(T /*x*/, const std::vector<int>& /*dims*/, int /*pos*/) {
17 // no-op
18}
19
20template <typename T>
21void 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 }
27 for (size_t i = 0; i < x.size(); ++i) {
28 resize(x[i], dims, pos);
29 }
30}
31} // namespace internal
32
42template <typename T>
43inline void resize(T& x, std::vector<int> dims) {
44 internal::resize(x, dims, 0U);
45}
46
47} // namespace math
48} // namespace stan
49
50#endif
void dims(const T_x &x, std::vector< int > &result)
matrix_cl overload of the dims helper function in prim/fun/dims.hpp.
Definition dims.hpp:21
void resize(Eigen::Matrix< T, R, C > &x, const std::vector< int > &dims, int pos)
Definition resize.hpp:11
void resize(T &x, std::vector< int > dims)
Recursively resize the specified vector of vectors, which must bottom out at scalar values,...
Definition resize.hpp:43
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...