Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 
5 #include <boost/math/tools/promotion.hpp>
9 
10 namespace stan {
11  namespace math {
12 
13  using Eigen::Dynamic;
14  using Eigen::Matrix;
15  using boost::math::tools::promote_args;
16 
17  template <typename T1, typename T2, int R, int C>
18  inline Matrix
19  <typename promote_args<T1, T2>::type, Dynamic, Dynamic>
20  quad_form_diag(const Matrix<T1, Dynamic, Dynamic>& mat,
21  const Matrix<T2, R, C>& vec) {
22  stan::math::check_vector("quad_form_diag", "vec", vec);
23  stan::math::check_square("quad_form_diag", "mat", mat);
24  int size = vec.size();
25  stan::math::check_equal("quad_form_diag", "matrix size", mat.rows(),
26  size);
27  Matrix<typename promote_args<T1, T2>::type, Dynamic, Dynamic>
28  result(size, size);
29  for (int i = 0; i < size; i++) {
30  result(i, i) = vec(i)*vec(i)*mat(i, i);
31  for (int j = i+1; j < size; ++j) {
32  typename promote_args<T1, T2>::type temp = vec(i)*vec(j);
33  result(j, i) = temp*mat(j, i);
34  result(i, j) = temp*mat(i, j);
35  }
36  }
37  return result;
38  }
39 
40  }
41 }
42 #endif
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.
Matrix< typename promote_args< T1, T2 >::type, Dynamic, Dynamic > quad_form_diag(const Matrix< T1, Dynamic, Dynamic > &mat, const Matrix< T2, R, C > &vec)
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:90
int size(const std::vector< T > &x)
Definition: size.hpp:11
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.

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