Automatic Differentiation
 
Loading...
Searching...
No Matches
mdivide_right.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MDIVIDE_RIGHT_HPP
2#define STAN_MATH_PRIM_FUN_MDIVIDE_RIGHT_HPP
3
7
8namespace stan {
9namespace math {
10
23template <typename EigMat1, typename EigMat2,
24 require_all_eigen_t<EigMat1, EigMat2>* = nullptr,
25 require_all_not_vt_fvar<EigMat1, EigMat2>* = nullptr>
26inline Eigen::Matrix<return_type_t<EigMat1, EigMat2>,
27 EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime>
28mdivide_right(const EigMat1& b, const EigMat2& A) {
29 using T_return = return_type_t<EigMat1, EigMat2>;
30 check_square("mdivide_right", "A", A);
31 check_multiplicable("mdivide_right", "b", b, "A", A);
32 if (A.size() == 0) {
33 return {b.rows(), 0};
34 }
35
36 return Eigen::Matrix<T_return, EigMat2::RowsAtCompileTime,
37 EigMat2::ColsAtCompileTime>(A)
38 .transpose()
39 .lu()
40 .solve(Eigen::Matrix<T_return, Eigen::Dynamic, Eigen::Dynamic>(b)
41 .transpose())
42 .transpose();
43}
44
45} // namespace math
46} // namespace stan
47
48#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.
Eigen::Matrix< value_type_t< EigMat1 >, EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime > mdivide_right(const EigMat1 &A, const EigMat2 &b)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...