Automatic Differentiation
 
Loading...
Searching...
No Matches
mdivide_left_spd.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MDIVIDE_LEFT_SPD_HPP
2#define STAN_MATH_PRIM_FUN_MDIVIDE_LEFT_SPD_HPP
3
8
9namespace stan {
10namespace math {
11
25template <typename EigMat1, typename EigMat2,
26 require_all_eigen_t<EigMat1, EigMat2>* = nullptr,
27 require_all_not_vt_var<EigMat1, EigMat2>* = nullptr>
28inline Eigen::Matrix<return_type_t<EigMat1, EigMat2>,
29 EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime>
30mdivide_left_spd(const EigMat1& A, const EigMat2& b) {
31 static constexpr const char* function = "mdivide_left_spd";
32 check_multiplicable(function, "A", A, "b", b);
33 const auto& A_ref = to_ref(A);
34 check_symmetric(function, "A", A_ref);
35 check_not_nan(function, "A", A_ref);
36 if (A.size() == 0) {
37 return {0, b.cols()};
38 }
39
40 auto llt
41 = Eigen::Matrix<return_type_t<EigMat1, EigMat2>,
42 EigMat1::RowsAtCompileTime, EigMat1::ColsAtCompileTime>(
43 A_ref)
44 .llt();
45 check_pos_definite(function, "A", llt);
46 return llt.solve(
47 Eigen::Matrix<return_type_t<EigMat1, EigMat2>, EigMat2::RowsAtCompileTime,
48 EigMat2::ColsAtCompileTime>(b));
49}
50
51} // namespace math
52} // namespace stan
53
54#endif
void check_symmetric(const char *function, const char *name, const matrix_cl< T > &y)
Check if the matrix_cl is symmetric.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
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< return_type_t< EigMat1, EigMat2 >, EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime > mdivide_left_spd(const EigMat1 &A, const EigMat2 &b)
Returns the solution of the system Ax=b where A is symmetric positive definite.
void check_pos_definite(const char *function, const char *name, const EigMat &y)
Check if the specified square, symmetric matrix is positive definite.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9