Automatic Differentiation
 
Loading...
Searching...
No Matches
one_hot_int_array.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_ONE_HOT_INT_ARRAY_HPP
2#define STAN_MATH_PRIM_FUN_ONE_HOT_INT_ARRAY_HPP
3
5#include <vector>
6
7namespace stan {
8namespace math {
9
20inline std::vector<int> one_hot_int_array(int K, int k) {
21 static constexpr const char* function = "one_hot_int_array";
22 check_positive(function, "size", K);
23 check_bounded(function, "k", k, 1, K);
24
25 std::vector<int> v(K, 0);
26 v[k - 1] = 1;
27 return v;
28}
29
30} // namespace math
31} // namespace stan
32
33#endif
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
std::vector< int > one_hot_int_array(int K, int k)
Return an integer array with 1 in the k-th position and zero elsewhere.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...