Automatic Differentiation
 
Loading...
Searching...
No Matches
append_row.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_APPEND_ROW_HPP
2#define STAN_MATH_PRIM_FUN_APPEND_ROW_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
30template <typename T1, typename T2, require_all_eigen_t<T1, T2>* = nullptr>
31inline auto append_row(const T1& A, const T2& B) {
32 using Eigen::Dynamic;
33 using Eigen::Matrix;
34 using T_return = return_type_t<T1, T2>;
35 constexpr int col_type
36 = (T1::ColsAtCompileTime == 1 && T2::ColsAtCompileTime == 1)
37 ? 1
38 : Eigen::Dynamic;
39
40 int Arows = A.rows();
41 int Brows = B.rows();
42 int Acols = A.cols();
43 int Bcols = B.cols();
44 check_size_match("append_row", "columns of A", Acols, "columns of B", Bcols);
45
46 Matrix<T_return, Dynamic, col_type> result(Arows + Brows, Acols);
47 result.topRows(Arows) = A.template cast<T_return>();
48 result.bottomRows(Brows) = B.template cast<T_return>();
49 return result;
50}
51
65template <typename Scal, typename ColVec,
68inline Eigen::Matrix<return_type_t<Scal, ColVec>, Eigen::Dynamic, 1> append_row(
69 const Scal& A, const ColVec& B) {
70 using Eigen::Dynamic;
71 using Eigen::Matrix;
72 using T_return = return_type_t<Scal, ColVec>;
73
74 Matrix<T_return, Dynamic, 1> result(B.size() + 1);
75 result << A, B.template cast<T_return>();
76 return result;
77}
78
92template <typename ColVec, typename Scal,
95inline Eigen::Matrix<return_type_t<ColVec, Scal>, Eigen::Dynamic, 1> append_row(
96 const ColVec& A, const Scal& B) {
97 using Eigen::Dynamic;
98 using Eigen::Matrix;
99 using T_return = return_type_t<ColVec, Scal>;
100
101 Matrix<T_return, Dynamic, 1> result(A.size() + 1);
102 result << A.template cast<T_return>(), B;
103 return result;
104}
105
106} // namespace math
107} // namespace stan
108
109#endif
auto append_row(Ta &&a, Tb &&b)
Stack the rows of the first argument on top of the second argument.
Definition append.hpp:183
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...