Stan Math Library  2.20.0
reverse mode automatic differentiation
quad_form_sym.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_QUAD_FORM_SYM_HPP
2 #define STAN_MATH_REV_MAT_FUN_QUAD_FORM_SYM_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
11 #include <type_traits>
12 
13 namespace stan {
14 namespace math {
15 
16 template <typename Ta, int Ra, int Ca, typename Tb, int Rb, int Cb>
17 inline typename std::enable_if<std::is_same<Ta, var>::value
18  || std::is_same<Tb, var>::value,
19  Eigen::Matrix<var, Cb, Cb> >::type
20 quad_form_sym(const Eigen::Matrix<Ta, Ra, Ca>& A,
21  const Eigen::Matrix<Tb, Rb, Cb>& B) {
22  check_square("quad_form", "A", A);
23  check_symmetric("quad_form_sym", "A", A);
24  check_multiplicable("quad_form_sym", "A", A, "B", B);
25 
28 
29  return baseVari->impl_->C_;
30 }
31 
32 template <typename Ta, int Ra, int Ca, typename Tb, int Rb>
33 inline typename std::enable_if<
34  std::is_same<Ta, var>::value || std::is_same<Tb, var>::value, var>::type
35 quad_form_sym(const Eigen::Matrix<Ta, Ra, Ca>& A,
36  const Eigen::Matrix<Tb, Rb, 1>& B) {
37  check_square("quad_form", "A", A);
38  check_symmetric("quad_form_sym", "A", A);
39  check_multiplicable("quad_form_sym", "A", A, "B", B);
40 
43 
44  return baseVari->impl_->C_(0, 0);
45 }
46 
47 } // namespace math
48 } // namespace stan
49 #endif
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
quad_form_vari_alloc< Ta, Ra, Ca, Tb, Rb, Cb > * impl_
Definition: quad_form.hpp:108
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
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< fvar< T >, CB, CB > quad_form_sym(const Eigen::Matrix< fvar< T >, RA, CA > &A, const Eigen::Matrix< double, RB, CB > &B)
void check_symmetric(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is symmetric.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.