Automatic Differentiation
 
Loading...
Searching...
No Matches
mdivide_left_ldlt.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_MDIVIDE_LEFT_LDLT_HPP
2#define STAN_MATH_FWD_FUN_MDIVIDE_LEFT_LDLT_HPP
3
9
10namespace stan {
11namespace math {
12
23template <typename T, typename EigMat,
24 require_eigen_vt<std::is_arithmetic, T>* = nullptr,
25 require_eigen_vt<is_fvar, EigMat>* = nullptr>
26inline Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic,
27 EigMat::ColsAtCompileTime>
28mdivide_left_ldlt(LDLT_factor<T>& A, const EigMat& b) {
29 using EigMatValueScalar = typename value_type_t<EigMat>::Scalar;
30 constexpr int R2 = EigMat::RowsAtCompileTime;
31 constexpr int C2 = EigMat::ColsAtCompileTime;
32 check_multiplicable("mdivide_left_ldlt", "A", A.matrix(), "b", b);
33
34 const auto& b_ref = to_ref(b);
35 Eigen::Matrix<EigMatValueScalar, R2, C2> b_val(b.rows(), b.cols());
36 Eigen::Matrix<EigMatValueScalar, R2, C2> b_der(b.rows(), b.cols());
37 for (int j = 0; j < b.cols(); j++) {
38 for (int i = 0; i < b.rows(); i++) {
39 b_val.coeffRef(i, j) = b_ref.coeff(i, j).val_;
40 b_der.coeffRef(i, j) = b_ref.coeff(i, j).d_;
41 }
42 }
43
44 return to_fvar(mdivide_left_ldlt(A, b_val), mdivide_left_ldlt(A, b_der));
45}
46
47} // namespace math
48} // namespace stan
49#endif
LDLT_factor is a structure that holds a matrix of type T and the LDLT of its values.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
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< EigMat >, Eigen::Dynamic, EigMat::ColsAtCompileTime > mdivide_left_ldlt(LDLT_factor< T > &A, const EigMat &b)
Returns the solution of the system Ax=b given an LDLT_factor of A.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
fvar< T > to_fvar(const T &x)
Definition to_fvar.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...