| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

quad_form_diag.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_DIAG_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_DIAG_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <boost/math/tools/promotion.hpp>
6 #include <stan/math/prim/mat/err/check_square.hpp>
7 #include <stan/math/prim/mat/err/check_vector.hpp>
8 #include <stan/math/prim/scal/err/check_equal.hpp>
9
10 namespace stan {
11 namespace math {
12
13 template <typename T1, typename T2, int R, int C>
14 inline Eigen::Matrix <
15 typename boost::math::tools::promote_args<T1, T2>::type,
16 Eigen::Dynamic, Eigen::Dynamic>
17 quad_form_diag(const Eigen::Matrix<T1, Eigen::Dynamic, Eigen::Dynamic>& mat,
18 const Eigen::Matrix<T2, R, C>& vec) {
19 using boost::math::tools::promote_args;
20 check_vector("quad_form_diag", "vec", vec);
21 check_square("quad_form_diag", "mat", mat);
22 int size = vec.size();
23 check_equal("quad_form_diag", "matrix size", mat.rows(),
24 size);
25 Eigen::Matrix<typename promote_args<T1, T2>::type,
26 Eigen::Dynamic, Eigen::Dynamic> result(size, size);
27 for (int i = 0; i < size; i++) {
28 result(i, i) = vec(i)*vec(i)*mat(i, i);
29 for (int j = i+1; j < size; ++j) {
30 typename promote_args<T1, T2>::type temp = vec(i)*vec(j);
31 result(j, i) = temp*mat(j, i);
32 result(i, j) = temp*mat(i, j);
33 }
34 }
35 return result;
36 }
37
38 }
39 }
40 #endif
stan::math::check_vector
bool check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Return true if the matrix is either a row vector or column vector.
Definition: check_vector.hpp:34
stan
Definition: log_sum_exp.hpp:8
check_equal.hpp
stan::math::check_equal
bool check_equal(const char *function, const char *name, const T_y &y, const T_eq &eq)
Return true if y is equal to eq.
Definition: check_equal.hpp:89
Eigen.hpp
check_vector.hpp
stan::math::size
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
stan::math::quad_form_diag
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, Eigen::Dynamic, Eigen::Dynamic > quad_form_diag(const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &mat, const Eigen::Matrix< T2, R, C > &vec)
Definition: quad_form_diag.hpp:17
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
check_square.hpp

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