Automatic Differentiation
 
Loading...
Searching...
No Matches
append_col.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_APPEND_COL_HPP
2#define STAN_MATH_PRIM_FUN_APPEND_COL_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
32template <typename T1, typename T2, typename = require_all_eigen_t<T1, T2>>
33inline auto append_col(const T1& A, const T2& B) {
34 using Eigen::Dynamic;
35 using Eigen::Matrix;
36 using T_return = return_type_t<T1, T2>;
37 constexpr int row_type
38 = (T1::RowsAtCompileTime == 1 && T2::RowsAtCompileTime == 1)
39 ? 1
40 : Eigen::Dynamic;
41
42 int Arows = A.rows();
43 int Brows = B.rows();
44 int Acols = A.cols();
45 int Bcols = B.cols();
46 check_size_match("append_col", "rows of A", Arows, "rows of B", Brows);
47
48 Matrix<T_return, row_type, Dynamic> result(Arows, Acols + Bcols);
49 result.leftCols(Acols) = A.template cast<T_return>();
50 result.rightCols(Bcols) = B.template cast<T_return>();
51 return result;
52}
53
68template <typename Scal, typename RowVec,
71inline Eigen::Matrix<return_type_t<Scal, RowVec>, 1, Eigen::Dynamic> append_col(
72 const Scal& A, const RowVec& B) {
73 using Eigen::Dynamic;
74 using Eigen::Matrix;
75 using T_return = return_type_t<Scal, RowVec>;
76
77 Matrix<T_return, 1, Dynamic> result(B.size() + 1);
78 result << A, B.template cast<T_return>();
79 return result;
80}
81
96template <typename RowVec, typename Scal,
99inline Eigen::Matrix<return_type_t<RowVec, Scal>, 1, Eigen::Dynamic> append_col(
100 const RowVec& A, const Scal& B) {
101 using Eigen::Dynamic;
102 using Eigen::Matrix;
103 using T_return = return_type_t<RowVec, Scal>;
104
105 Matrix<T_return, 1, Dynamic> result(A.size() + 1);
106 result << A.template cast<T_return>(), B;
107 return result;
108}
109
110} // namespace math
111} // namespace stan
112
113#endif
auto append_col(Ta &&a, Tb &&b)
Stack the cols of the arguments.
Definition append.hpp:346
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 ...