1 #ifndef STAN_MATH_REV_MAT_FUN_MDIVIDE_LEFT_TRI_HPP 2 #define STAN_MATH_REV_MAT_FUN_MDIVIDE_LEFT_TRI_HPP 15 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
27 const Eigen::Matrix<var, R2, C2> &B)
31 A_(reinterpret_cast<double *>(
34 C_(reinterpret_cast<double *>(
37 variRefA_(reinterpret_cast<
vari **>(
39 * (A.
rows() + 1) / 2))),
40 variRefB_(reinterpret_cast<
vari **>(
43 variRefC_(reinterpret_cast<
vari **>(
53 variRefA_[pos++] = A(i, j).vi_;
57 variRefA_[pos++] = A(i, j).vi_;
63 A_[pos++] = A(i, j).val();
70 variRefB_[pos] = B(i, j).vi_;
71 C_[pos++] = B(i, j).val();
75 Matrix<double, R1, C2> C(M_, N_);
76 C = Map<Matrix<double, R1, C2> >(
C_,
M_,
N_);
78 C = Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
79 .
template triangularView<TriView>()
86 variRefC_[pos] =
new vari(C_[pos],
false);
95 Matrix<double, R1, C1> adjA(M_, M_);
96 Matrix<double, R2, C2> adjB(M_, N_);
97 Matrix<double, R1, C2> adjC(M_, N_);
100 for (
size_type j = 0; j < adjC.cols(); j++)
101 for (
size_type i = 0; i < adjC.rows(); i++)
102 adjC(i, j) = variRefC_[pos++]->
adj_;
104 adjB = Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
105 .
template triangularView<TriView>()
113 for (
size_type j = 0; j < adjA.cols(); j++)
114 for (
size_type i = j; i < adjA.rows(); i++)
115 variRefA_[pos++]->
adj_ += adjA(i, j);
117 for (
size_type j = 0; j < adjA.cols(); j++)
119 variRefA_[pos++]->
adj_ += adjA(i, j);
123 for (
size_type j = 0; j < adjB.cols(); j++)
124 for (
size_type i = 0; i < adjB.rows(); i++)
125 variRefB_[pos++]->
adj_ += adjB(i, j);
129 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
140 const Eigen::Matrix<var, R2, C2> &B)
144 A_(reinterpret_cast<double *>(
147 C_(reinterpret_cast<double *>(
150 variRefB_(reinterpret_cast<
vari **>(
153 variRefC_(reinterpret_cast<
vari **>(
169 variRefB_[pos] = B(i, j).vi_;
170 C_[pos++] = B(i, j).val();
174 Matrix<double, R1, C2> C(M_, N_);
175 C = Map<Matrix<double, R1, C2> >(
C_,
M_,
N_);
177 C = Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
178 .
template triangularView<TriView>()
185 variRefC_[pos] =
new vari(C_[pos],
false);
194 Matrix<double, R2, C2> adjB(M_, N_);
195 Matrix<double, R1, C2> adjC(M_, N_);
198 for (
size_type j = 0; j < adjC.cols(); j++)
199 for (
size_type i = 0; i < adjC.rows(); i++)
200 adjC(i, j) = variRefC_[pos++]->
adj_;
202 adjB = Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
203 .
template triangularView<TriView>()
208 for (
size_type j = 0; j < adjB.cols(); j++)
209 for (
size_type i = 0; i < adjB.rows(); i++)
210 variRefB_[pos++]->
adj_ += adjB(i, j);
214 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
225 const Eigen::Matrix<double, R2, C2> &B)
229 A_(reinterpret_cast<double *>(
232 C_(reinterpret_cast<double *>(
235 variRefA_(reinterpret_cast<
vari **>(
237 * (A.
rows() + 1) / 2))),
238 variRefC_(reinterpret_cast<
vari **>(
248 variRefA_[pos++] = A(i, j).vi_;
252 variRefA_[pos++] = A(i, j).vi_;
258 A_[pos++] = A(i, j).val();
262 Matrix<double, R1, C2> C(M_, N_);
263 C = Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
264 .
template triangularView<TriView>()
271 variRefC_[pos] =
new vari(C_[pos],
false);
280 Matrix<double, R1, C1> adjA(M_, M_);
281 Matrix<double, R1, C2> adjC(M_, N_);
284 for (
size_type j = 0; j < adjC.cols(); j++)
285 for (
size_type i = 0; i < adjC.rows(); i++)
286 adjC(i, j) = variRefC_[pos++]->
adj_;
289 = -Map<Matrix<double, R1, C1> >(
A_,
M_,
M_)
290 .
template triangularView<TriView>()
293 * Map<Matrix<double, R1, C2> >(C_, M_, N_).
transpose());
297 for (
size_type j = 0; j < adjA.cols(); j++)
298 for (
size_type i = j; i < adjA.rows(); i++)
299 variRefA_[pos++]->
adj_ += adjA(i, j);
301 for (
size_type j = 0; j < adjA.cols(); j++)
303 variRefA_[pos++]->
adj_ += adjA(i, j);
309 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
311 const Eigen::Matrix<var, R1, C1> &A,
const Eigen::Matrix<var, R2, C2> &b) {
312 Eigen::Matrix<var, R1, C2> res(b.rows(), b.cols());
325 for (
size_type j = 0; j < res.cols(); j++)
326 for (
size_type i = 0; i < res.rows(); i++)
327 res(i, j).vi_ = baseVari->
variRefC_[pos++];
331 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
333 const Eigen::Matrix<double, R1, C1> &A,
334 const Eigen::Matrix<var, R2, C2> &b) {
335 Eigen::Matrix<var, R1, C2> res(b.rows(), b.cols());
348 for (
size_type j = 0; j < res.cols(); j++)
349 for (
size_type i = 0; i < res.rows(); i++)
350 res(i, j).vi_ = baseVari->
variRefC_[pos++];
354 template <
int TriView,
int R1,
int C1,
int R2,
int C2>
356 const Eigen::Matrix<var, R1, C1> &A,
357 const Eigen::Matrix<double, R2, C2> &b) {
358 Eigen::Matrix<var, R1, C2> res(b.rows(), b.cols());
371 for (
size_type j = 0; j < res.cols(); j++)
372 for (
size_type i = 0; i < res.rows(); i++)
373 res(i, j).vi_ = baseVari->
variRefC_[pos++];
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
mdivide_left_tri_vd_vari(const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< double, R2, C2 > &B)
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
The variable implementation base class.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R1, C2 > mdivide_left_tri(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &b)
Returns the solution of the system Ax=b when A is triangular.
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
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.
matrix_cl transpose(const matrix_cl &src)
Takes the transpose of the matrix on the OpenCL device.
mdivide_left_tri_vv_vari(const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &B)
vari(double x)
Construct a variable implementation from a value.
mdivide_left_tri_dv_vari(const Eigen::Matrix< double, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &B)
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
This struct always provides access to the autodiff stack using the singleton pattern.
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...