Automatic Differentiation
 
Loading...
Searching...
No Matches
quad_form_diag.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_QUAD_FORM_DIAG_HPP
2#define STAN_MATH_PRIM_FUN_QUAD_FORM_DIAG_HPP
3
7
8namespace stan {
9namespace math {
10
11template <typename EigMat, typename EigVec, require_eigen_t<EigMat>* = nullptr,
12 require_eigen_vector_t<EigVec>* = nullptr>
13inline auto quad_form_diag(const EigMat& mat, const EigVec& vec) {
14 check_square("quad_form_diag", "mat", mat);
15 check_size_match("quad_form_diag", "rows of mat", mat.rows(), "size of vec",
16 vec.size());
17 return make_holder(
18 [](const auto& v, const auto& x) {
19 return v.asDiagonal() * x * v.asDiagonal();
20 },
21 to_ref(vec), to_ref(mat));
22}
23
24} // namespace math
25} // namespace stan
26
27#endif
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
auto quad_form_diag(const EigMat &mat, const EigVec &vec)
auto make_holder(const F &func, Args &&... args)
Constructs an expression from given arguments using given functor.
Definition holder.hpp:352
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...