Stan Math Library  2.9.0
reverse mode automatic differentiation
diag_post_multiply.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_DIAG_POST_MULTIPLY_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_DIAG_POST_MULTIPLY_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
6 #include <stdexcept>
7 
8 namespace stan {
9  namespace math {
10 
11  template <typename T1, typename T2, int R1, int C1, int R2, int C2>
12  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
13  R1, C1>
14  diag_post_multiply(const Eigen::Matrix<T1, R1, C1>& m1,
15  const Eigen::Matrix<T2, R2, C2>& m2) {
16  if (m2.cols() != 1 && m2.rows() != 1)
17  throw std::domain_error("m2 must be a vector");
18  int m1_cols = m1.cols();
19  if (m2.size() != m1_cols)
20  throw std::domain_error("m2 must have same length as m1 has columns");
21  int m1_rows = m1.rows();
22  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
23  R1, C1>
24  result(m1_rows, m1_cols);
25 
26  for (int j = 0; j < m1_cols; ++j)
27  for (int i = 0; i < m1_rows; ++i)
28  result(i, j) = m2(j) * m1(i, j);
29  return result;
30  }
31 
32  }
33 }
34 #endif
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R1, C1 > diag_post_multiply(const Eigen::Matrix< T1, R1, C1 > &m1, const Eigen::Matrix< T2, R2, C2 > &m2)

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