Automatic Differentiation
 
Loading...
Searching...
No Matches
mdivide_right_tri.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MDIVIDE_RIGHT_TRI_HPP
2#define STAN_MATH_PRIM_FUN_MDIVIDE_RIGHT_TRI_HPP
3
8
9namespace stan {
10namespace math {
11
27template <Eigen::UpLoType TriView, typename EigMat1, typename EigMat2,
28 require_all_eigen_t<EigMat1, EigMat2>* = nullptr>
29inline auto mdivide_right_tri(const EigMat1& b, const EigMat2& A) {
30 check_square("mdivide_right_tri", "A", A);
31 check_multiplicable("mdivide_right_tri", "b", b, "A", A);
32 if (TriView != Eigen::Lower && TriView != Eigen::Upper) {
33 throw_domain_error("mdivide_right_tri",
34 "triangular view must be Eigen::Lower or Eigen::Upper",
35 "", "");
36 }
37 using T_return = return_type_t<EigMat1, EigMat2>;
38 using ret_type = Eigen::Matrix<T_return, Eigen::Dynamic, Eigen::Dynamic>;
39 if (A.rows() == 0) {
40 return ret_type(b.rows(), 0);
41 }
42
43 return ret_type(A)
44 .template triangularView<TriView>()
45 .transpose()
46 .solve(ret_type(b).transpose())
47 .transpose()
48 .eval();
49}
50
51} // namespace math
52} // namespace stan
53
54#endif
auto transpose(Arg &&a)
Transposes a kernel generator expression.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
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.
auto mdivide_right_tri(const EigMat1 &b, const EigMat2 &A)
Returns the solution of the system xA=b when A is triangular.
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...