1 #ifndef STAN_MATH_PRIM_FUN_UNITSPACED_ARRAY_HPP
2 #define STAN_MATH_PRIM_FUN_UNITSPACED_ARRAY_HPP
3 
4 #include <stan/math/prim/err.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 #include <stan/math/prim/fun/fabs.hpp>
7 #include <vector>
8 
9 namespace stan {
10 namespace math {
11 
12 /**
13  * Return an array of integers in an ordered sequence.
14  *
15  * This produces an array from low to high (included).
16  *
17  * @param low smallest integer
18  * @param high largest integer
19  * @return An array of size (high - low + 1) with elements linearly spaced
20  * between low and high.
21  * @throw std::domain_error if high is less than low.
22  */
unitspaced_array(int low,int high)23 inline std::vector<int> unitspaced_array(int low, int high) {
24   static const char* function = "unitspaced_array";
25   check_greater_or_equal(function, "high", high, low);
26 
27   int K = std::abs(high - low + 1);
28   std::vector<int> result(K);
29   Eigen::Map<Eigen::VectorXi>(result.data(), K)
30       = Eigen::VectorXi::LinSpaced(K, low, high);
31   return result;
32 }
33 
34 }  // namespace math
35 }  // namespace stan
36 
37 #endif
38