Automatic Differentiation
 
Loading...
Searching...
No Matches
linspaced_array.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LINSPACED_ARRAY_HPP
2#define STAN_MATH_PRIM_FUN_LINSPACED_ARRAY_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
26inline std::vector<double> linspaced_array(int K, double low, double high) {
27 static constexpr const char* function = "linspaced_array";
28 check_nonnegative(function, "size", K);
29 check_finite(function, "low", low);
30 check_finite(function, "high", high);
31 check_greater_or_equal(function, "high", high, low);
32
33 if (K == 0) {
34 return {};
35 }
36
37 Eigen::VectorXd v = Eigen::VectorXd::LinSpaced(K, low, high);
38 return {&v[0], &v[0] + K};
39}
40
41} // namespace math
42} // namespace stan
43
44#endif
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not greater or equal than low.
std::vector< double > linspaced_array(int K, double low, double high)
Return an array of linearly spaced elements.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...