1 #ifndef STAN_MATH_PRIM_FUN_SUB_ROW_HPP
2 #define STAN_MATH_PRIM_FUN_SUB_ROW_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 1 x ncols subrow starting at (i-1, j-1).
12 *
13 * @tparam T type of the matrix
14 * @param m Matrix Input matrix.
15 * @param i Starting row + 1.
16 * @param j Starting column + 1.
17 * @param ncols Number of columns in block.
18 * @throw std::out_of_range if either index is out of range.
19 */
20 template <
21 typename T, require_matrix_t<T>* = nullptr,
22 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr>
sub_row(const T & m,size_t i,size_t j,size_t ncols)23 inline auto sub_row(const T& m, size_t i, size_t j, size_t ncols) {
24 check_row_index("sub_row", "i", m, i);
25 check_column_index("sub_row", "j", m, j);
26 if (ncols > 0) {
27 check_column_index("sub_col", "j+ncols-1", m, j + ncols - 1);
28 }
29 return m.row(i - 1).segment(j - 1, ncols);
30 }
31
32 } // namespace math
33 } // namespace stan
34
35 #endif
36