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>
11inline void resize(Eigen::Matrix<T, R, C>& x, const std::vector<int>& dims,
12 int pos) {
13 x.resize(dims[pos], dims[pos + 1]);
14}
15
16template <typename T>
17inline void resize(T /*x*/, const std::vector<int>& /*dims*/, int /*pos*/) {
18 // no-op
19}
20
21template <typename T>
22inline void resize(std::vector<T>& x, const std::vector<int>& dims, int pos) {
23 x.resize(dims[pos]);
24 ++pos;
25 if (pos >= static_cast<int>(dims.size())) {
26 return; // skips lowest loop to scalar
27 }
28 for (size_t i = 0; i < x.size(); ++i) {
29 resize(x[i], dims, pos);
30 }
31}
32} // namespace internal
33
43template <typename T>
44inline void resize(T& x, std::vector<int> dims) {
45 internal::resize(x, dims, 0U);
46}
47
48} // namespace math
49} // namespace stan
50
51#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:44
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...