1 #ifndef STAN__AGRAD__FWD__MATRIX__COLUMNS_MDIVIDE_LEFT_HPP
2 #define STAN__AGRAD__FWD__MATRIX__COLUMNS_MDIVIDE_LEFT_HPP
22 template <
typename T,
int R1,
int C1,
int R2,
int C2>
24 Eigen::Matrix<fvar<T>,R1,C2>
26 const Eigen::Matrix<
fvar<T>,R2,C2> &b) {
34 Eigen::Matrix<T,R1,C2> inv_A_mult_b(A.rows(),b.cols());
35 Eigen::Matrix<T,R1,C2> inv_A_mult_deriv_b(A.rows(),b.cols());
36 Eigen::Matrix<T,R1,C1> inv_A_mult_deriv_A(A.rows(),A.cols());
37 Eigen::Matrix<T,R1,C1> val_A(A.rows(),A.cols());
38 Eigen::Matrix<T,R1,C1> deriv_A(A.rows(),A.cols());
39 Eigen::Matrix<T,R2,C2> val_b(b.rows(),b.cols());
40 Eigen::Matrix<T,R2,C2> deriv_b(b.rows(),b.cols());
42 for (
int j = 0; j < A.cols(); j++) {
43 for(
int i = 0; i < A.rows(); i++) {
44 val_A(i,j) = A(i,j).val_;
45 deriv_A(i,j) = A(i,j).d_;
49 for (
int j = 0; j < b.cols(); j++) {
50 for(
int i = 0; i < b.rows(); i++) {
51 val_b(i,j) = b(i,j).val_;
52 deriv_b(i,j) = b(i,j).d_;
60 Eigen::Matrix<T,R1,C2> deriv(A.rows(), b.cols());
61 deriv = inv_A_mult_deriv_b -
multiply(inv_A_mult_deriv_A, inv_A_mult_b);
66 template <
typename T,
int R1,
int C1,
int R2,
int C2>
68 Eigen::Matrix<fvar<T>,R1,C2>
70 const Eigen::Matrix<
fvar<T>,R2,C2> &b) {
78 Eigen::Matrix<T,R2,C2> val_b(b.rows(),b.cols());
79 Eigen::Matrix<T,R2,C2> deriv_b(b.rows(),b.cols());
81 for (
int j = 0; j < b.cols(); j++) {
82 for(
int i = 0; i < b.rows(); i++) {
83 val_b(i,j) = b(i,j).val_;
84 deriv_b(i,j) = b(i,j).d_;
92 template <
typename T,
int R1,
int C1,
int R2,
int C2>
94 Eigen::Matrix<fvar<T>,R1,C2>
96 const Eigen::Matrix<double,R2,C2> &b) {
104 Eigen::Matrix<T,R1,C2>
105 inv_A_mult_b(A.rows(),b.cols());
106 Eigen::Matrix<T,R1,C1> inv_A_mult_deriv_A(A.rows(),A.cols());
107 Eigen::Matrix<T,R1,C1> val_A(A.rows(),A.cols());
108 Eigen::Matrix<T,R1,C1> deriv_A(A.rows(),A.cols());
110 for (
int j = 0; j < A.cols(); j++) {
111 for(
int i = 0; i < A.rows(); i++) {
112 val_A(i,j) = A(i,j).val_;
113 deriv_A(i,j) = A(i,j).d_;
120 Eigen::Matrix<T,R1,C2> deriv(A.rows(), b.cols());
121 deriv = -
multiply(inv_A_mult_deriv_A, inv_A_mult_b);
Eigen::Matrix< fvar< T >, R1, C2 > mdivide_left(const Eigen::Matrix< fvar< T >, R1, C1 > &A, const Eigen::Matrix< fvar< T >, R2, C2 > &b)
fvar< T > to_fvar(const T &x)
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
bool check_multiplicable(const char *function, const T1 &y1, const char *name1, const T2 &y2, const char *name2, T_result *result)
boost::enable_if_c< boost::is_arithmetic< T >::value, Eigen::Matrix< double, R, C > >::type multiply(const Eigen::Matrix< double, R, C > &m, T c)
Return specified matrix multiplied by specified scalar.
bool check_square(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is square.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R1, C2 > mdivide_left(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &b)
Returns the solution of the system Ax=b.