| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

quad_form_sym.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_QUAD_FORM_SYM_HPP
2 #define STAN_MATH_FWD_MAT_FUN_QUAD_FORM_SYM_HPP
3
4 #include <stan/math/fwd/core.hpp>
5 #include <stan/math/fwd/mat/fun/multiply.hpp>
6 #include <stan/math/fwd/mat/fun/dot_product.hpp>
7 #include <stan/math/prim/mat/fun/quad_form_sym.hpp>
8
9 namespace stan {
10 namespace math {
11
12 template<int RA, int CA, int RB, int CB, typename T>
13 inline Eigen::Matrix<fvar<T>, CB, CB>
14 quad_form_sym(const Eigen::Matrix<fvar<T>, RA, CA>& A,
15 const Eigen::Matrix<double, RB, CB>& B) {
16 check_square("quad_form_sym", "A", A);
17 check_multiplicable("quad_form_sym",
18 "A", A,
19 "B", B);
20 check_symmetric("quad_form_sym", "A", A);
21 Eigen::Matrix<fvar<T>, CB, CB>
22 ret(multiply(transpose(B), multiply(A, B)));
23 return T(0.5) * (ret + transpose(ret));
24 }
25
26 template<int RA, int CA, int RB, typename T>
27 inline fvar<T>
28 quad_form_sym(const Eigen::Matrix<fvar<T>, RA, CA>& A,
29 const Eigen::Matrix<double, RB, 1>& B) {
30 check_square("quad_form_sym", "A", A);
31 check_multiplicable("quad_form_sym",
32 "A", A,
33 "B", B);
34 check_symmetric("quad_form_sym", "A", A);
35 return dot_product(B, multiply(A, B));
36 }
37 template<int RA, int CA, int RB, int CB, typename T>
38 inline Eigen::Matrix<fvar<T>, CB, CB>
39 quad_form_sym(const Eigen::Matrix<double, RA, CA>& A,
40 const Eigen::Matrix<fvar<T>, RB, CB>& B) {
41 check_square("quad_form_sym", "A", A);
42 check_multiplicable("quad_form_sym",
43 "A", A,
44 "B", B);
45 check_symmetric("quad_form_sym", "A", A);
46 Eigen::Matrix<fvar<T>, CB, CB>
47 ret(multiply(transpose(B), multiply(A, B)));
48 return T(0.5) * (ret + transpose(ret));
49 }
50
51 template<int RA, int CA, int RB, typename T>
52 inline fvar<T>
53 quad_form_sym(const Eigen::Matrix<double, RA, CA>& A,
54 const Eigen::Matrix<fvar<T>, RB, 1>& B) {
55 check_square("quad_form_sym", "A", A);
56 check_multiplicable("quad_form_sym",
57 "A", A,
58 "B", B);
59 check_symmetric("quad_form_sym", "A", A);
60 return dot_product(B, multiply(A, B));
61 }
62 }
63 }
64
65 #endif
66
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::multiply
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:20
multiply.hpp
quad_form_sym.hpp
stan::math::check_multiplicable
bool check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Return true if the matrices can be multiplied.
Definition: check_multiplicable.hpp:32
dot_product.hpp
stan::math::dot_product
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Definition: dot_product.hpp:18
stan::math::quad_form_sym
Eigen::Matrix< fvar< T >, CB, CB > quad_form_sym(const Eigen::Matrix< fvar< T >, RA, CA > &A, const Eigen::Matrix< double, RB, CB > &B)
Definition: quad_form_sym.hpp:14
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:36
stan::math::transpose
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
stan::math::fvar
Definition: fvar.hpp:12

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