1#ifndef STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_HPP
2#define STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_HPP
16template <
typename EigMat1,
typename EigMat2,
17 require_all_eigen_vt<is_fvar, EigMat1, EigMat2>* =
nullptr,
18 require_vt_same<EigMat1, EigMat2>* =
nullptr>
19inline Eigen::Matrix<value_type_t<EigMat1>, EigMat1::RowsAtCompileTime,
20 EigMat2::ColsAtCompileTime>
23 constexpr int R1 = EigMat1::RowsAtCompileTime;
24 constexpr int C1 = EigMat1::ColsAtCompileTime;
25 constexpr int R2 = EigMat2::RowsAtCompileTime;
26 constexpr int C2 = EigMat2::ColsAtCompileTime;
34 Eigen::Matrix<T, R1, C1> val_A(A.rows(), A.cols());
35 Eigen::Matrix<T, R1, C1> deriv_A(A.rows(), A.cols());
36 Eigen::Matrix<T, R2, C2> val_b(b.rows(), b.cols());
37 Eigen::Matrix<T, R2, C2> deriv_b(b.rows(), b.cols());
39 const Eigen::Ref<const plain_type_t<EigMat1>>& A_ref = A;
40 for (
int j = 0; j < A.cols(); j++) {
41 for (
int i = 0; i < A.rows(); i++) {
42 val_A.coeffRef(i, j) = A_ref.coeff(i, j).val_;
43 deriv_A.coeffRef(i, j) = A_ref.coeff(i, j).d_;
47 const Eigen::Ref<const plain_type_t<EigMat2>>& b_ref = b;
48 for (
int j = 0; j < b.cols(); j++) {
49 for (
int i = 0; i < b.rows(); i++) {
50 val_b.coeffRef(i, j) = b_ref.coeff(i, j).val_;
51 deriv_b.coeffRef(i, j) = b_ref.coeff(i, j).d_;
55 Eigen::Matrix<T, R1, C2> A_mult_inv_b =
mdivide_right(val_A, val_b);
62template <
typename EigMat1,
typename EigMat2,
65inline Eigen::Matrix<value_type_t<EigMat1>, EigMat1::RowsAtCompileTime,
66 EigMat2::ColsAtCompileTime>
69 constexpr int R1 = EigMat1::RowsAtCompileTime;
70 constexpr int C1 = EigMat1::ColsAtCompileTime;
78 Eigen::Matrix<T, R1, C1> val_A(A.rows(), A.cols());
79 Eigen::Matrix<T, R1, C1> deriv_A(A.rows(), A.cols());
81 const Eigen::Ref<const plain_type_t<EigMat1>>& A_ref = A;
82 for (
int j = 0; j < A.cols(); j++) {
83 for (
int i = 0; i < A.rows(); i++) {
84 val_A.coeffRef(i, j) = A_ref.coeff(i, j).val_;
85 deriv_A.coeffRef(i, j) = A_ref.coeff(i, j).d_;
92template <
typename EigMat1,
typename EigMat2,
93 require_eigen_vt<std::is_arithmetic, EigMat1>* =
nullptr,
94 require_eigen_vt<is_fvar, EigMat2>* =
nullptr>
95inline Eigen::Matrix<value_type_t<EigMat2>, EigMat1::RowsAtCompileTime,
96 EigMat2::ColsAtCompileTime>
99 constexpr int R1 = EigMat1::RowsAtCompileTime;
100 constexpr int R2 = EigMat2::RowsAtCompileTime;
101 constexpr int C2 = EigMat2::ColsAtCompileTime;
106 return {A.rows(), 0};
109 Eigen::Matrix<T, R2, C2> val_b(b.rows(), b.cols());
110 Eigen::Matrix<T, R2, C2> deriv_b(b.rows(), b.cols());
112 const Eigen::Ref<const plain_type_t<EigMat2>>& b_ref = b;
113 for (
int j = 0; j < b.cols(); j++) {
114 for (
int i = 0; i < b.rows(); i++) {
115 val_b.coeffRef(i, j) = b_ref.coeff(i, j).val_;
116 deriv_b.coeffRef(i, j) = b_ref.coeff(i, j).d_;
120 Eigen::Matrix<T, R1, C2> A_mult_inv_b =
mdivide_right(A, val_b);
require_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check... > > require_eigen_vt
Require type satisfies is_eigen.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
Eigen::Matrix< value_type_t< EigMat1 >, EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime > mdivide_right(const EigMat1 &A, const EigMat2 &b)
fvar< T > to_fvar(const T &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...