Automatic Differentiation
 
Loading...
Searching...
No Matches
get_base1.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_GET_BASE1_HPP
2#define STAN_MATH_PRIM_FUN_GET_BASE1_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
27template <typename T>
28inline const T& get_base1(const std::vector<T>& x, size_t i,
29 const char* error_msg, size_t idx) {
30 check_range("[]", "x", x.size(), i, idx, error_msg);
31 return x[i - 1];
32}
33
50template <typename T>
51inline const T& get_base1(const std::vector<std::vector<T> >& x, size_t i1,
52 size_t i2, const char* error_msg, size_t idx) {
53 check_range("[]", "x", x.size(), i1, idx, error_msg);
54 return get_base1(x[i1 - 1], i2, error_msg, idx + 1);
55}
56
74template <typename T>
75inline const T& get_base1(const std::vector<std::vector<std::vector<T> > >& x,
76 size_t i1, size_t i2, size_t i3,
77 const char* error_msg, size_t idx) {
78 check_range("[]", "x", x.size(), i1, idx, error_msg);
79 return get_base1(x[i1 - 1], i2, i3, error_msg, idx + 1);
80}
81
100template <typename T>
101inline const T& get_base1(
102 const std::vector<std::vector<std::vector<std::vector<T> > > >& x,
103 size_t i1, size_t i2, size_t i3, size_t i4, const char* error_msg,
104 size_t idx) {
105 check_range("[]", "x", x.size(), i1, idx, error_msg);
106 return get_base1(x[i1 - 1], i2, i3, i4, error_msg, idx + 1);
107}
108
128template <typename T>
129inline const T& get_base1(
130 const std::vector<
131 std::vector<std::vector<std::vector<std::vector<T> > > > >& x,
132 size_t i1, size_t i2, size_t i3, size_t i4, size_t i5,
133 const char* error_msg, size_t idx) {
134 check_range("[]", "x", x.size(), i1, idx, error_msg);
135 return get_base1(x[i1 - 1], i2, i3, i4, i5, error_msg, idx + 1);
136}
137
158template <typename T>
159inline const T& get_base1(
160 const std::vector<std::vector<
161 std::vector<std::vector<std::vector<std::vector<T> > > > > >& x,
162 size_t i1, size_t i2, size_t i3, size_t i4, size_t i5, size_t i6,
163 const char* error_msg, size_t idx) {
164 check_range("[]", "x", x.size(), i1, idx, error_msg);
165 return get_base1(x[i1 - 1], i2, i3, i4, i5, i6, error_msg, idx + 1);
166}
167
189template <typename T>
190inline const T& get_base1(
191 const std::vector<std::vector<std::vector<
192 std::vector<std::vector<std::vector<std::vector<T> > > > > > >& x,
193 size_t i1, size_t i2, size_t i3, size_t i4, size_t i5, size_t i6, size_t i7,
194 const char* error_msg, size_t idx) {
195 check_range("[]", "x", x.size(), i1, idx, error_msg);
196 return get_base1(x[i1 - 1], i2, i3, i4, i5, i6, i7, error_msg, idx + 1);
197}
198
221template <typename T>
222inline const T& get_base1(
223 const std::vector<std::vector<std::vector<std::vector<
224 std::vector<std::vector<std::vector<std::vector<T> > > > > > > >& x,
225 size_t i1, size_t i2, size_t i3, size_t i4, size_t i5, size_t i6, size_t i7,
226 size_t i8, const char* error_msg, size_t idx) {
227 check_range("[]", "x", x.size(), i1, idx, error_msg);
228 return get_base1(x[i1 - 1], i2, i3, i4, i5, i6, i7, i8, error_msg, idx + 1);
229}
230
251template <typename EigMat, require_eigen_t<EigMat>* = nullptr,
252 require_not_eigen_vector_t<EigMat>* = nullptr>
253inline Eigen::Matrix<value_type_t<EigMat>, 1, Eigen::Dynamic> get_base1(
254 const EigMat& x, size_t m, const char* error_msg, size_t idx) {
255 check_range("[]", "rows of x", x.rows(), m, idx, error_msg);
256 return x.row(m - 1);
257}
258
276template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
277inline const value_type_t<EigMat>& get_base1(const EigMat& x, size_t m,
278 size_t n, const char* error_msg,
279 size_t idx) {
280 check_range("[]", "rows of x", x.rows(), m, idx, error_msg);
281 check_range("[]", "cols of x", x.cols(), n, idx + 1, error_msg);
282 return x.coeff(m - 1, n - 1);
283}
284
300template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
301inline const value_type_t<EigVec>& get_base1(const EigVec& x, size_t m,
302 const char* error_msg,
303 size_t idx) {
304 check_range("[]", "x", x.size(), m, idx, error_msg);
305 return x.coeff(m - 1);
306}
307
308} // namespace math
309} // namespace stan
310
311#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Check if specified index is within range.
const T & get_base1(const std::vector< T > &x, size_t i, const char *error_msg, size_t idx)
Return a reference to the value of the specified vector at the specified base-one index.
Definition get_base1.hpp:28
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...