Stan Math Library  2.14.0
reverse mode automatic differentiation
diag_pre_multiply.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_DIAG_PRE_MULTIPLY_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_DIAG_PRE_MULTIPLY_HPP
3 
7 #include <boost/math/tools/promotion.hpp>
8 
9 namespace stan {
10  namespace math {
11 
12  template <typename T1, typename T2, int R1, int C1, int R2, int C2>
13  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
14  R2, C2>
15  diag_pre_multiply(const Eigen::Matrix<T1, R1, C1>& m1,
16  const Eigen::Matrix<T2, R2, C2>& m2) {
17  check_vector("diag_pre_multiply", "m1", m1);
18  int m2_rows = m2.rows();
19  check_size_match("diag_pre_multiply",
20  "m1.size()", m1.size(),
21  "m2.rows()", m2_rows);
22  int m2_cols = m2.cols();
23  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
24  R2, C2>
25  result(m2_rows, m2_cols);
26  for (int j = 0; j < m2_cols; ++j)
27  for (int i = 0; i < m2_rows; ++i)
28  result(i, j) = m1(i) * m2(i, j);
29  return result;
30  }
31 
32  }
33 }
34 #endif
void check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Check if the matrix is either a row vector or column vector.
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.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R2, C2 > diag_pre_multiply(const Eigen::Matrix< T1, R1, C1 > &m1, const Eigen::Matrix< T2, R2, C2 > &m2)

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