1 #ifndef STAN_MATH_PRIM_FUN_LINSPACED_ROW_VECTOR_HPP
2 #define STAN_MATH_PRIM_FUN_LINSPACED_ROW_VECTOR_HPP
3
4 #include <stan/math/prim/err.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6
7 namespace stan {
8 namespace math {
9
10 /**
11 * Return a row vector of linearly spaced elements.
12 *
13 * This produces a row vector from low to high (inclusive) with elements spaced
14 * as (high - low) / (K - 1). For K=1, the vector will contain the high value;
15 * for K=0 it returns an empty vector.
16 *
17 * @param K size of the row vector
18 * @param low smallest value
19 * @param high largest value
20 * @return A row vector of size K with elements linearly spaced between
21 * low and high.
22 * @throw std::domain_error if K is negative, if low is nan or infinite,
23 * if high is nan or infinite, or if high is less than low.
24 */
linspaced_row_vector(int K,double low,double high)25 inline auto linspaced_row_vector(int K, double low, double high) {
26 static const char* function = "linspaced_row_vector";
27 check_nonnegative(function, "size", K);
28 check_finite(function, "low", low);
29 check_finite(function, "high", high);
30 check_greater_or_equal(function, "high", high, low);
31
32 return Eigen::RowVectorXd::LinSpaced(K, low, high);
33 }
34
35 } // namespace math
36 } // namespace stan
37
38 #endif
39