1 #ifndef STAN__MATH__MATRIX__DIAG_PRE_MULTIPLY_HPP
2 #define STAN__MATH__MATRIX__DIAG_PRE_MULTIPLY_HPP
5 #include <boost/math/tools/promotion.hpp>
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, R2, C2>
14 const Eigen::Matrix<T2,R2,C2>& m2) {
15 if (m1.cols() != 1 && m1.rows() != 1)
16 throw std::domain_error(
"m1 must be a vector");
17 int m2_rows = m2.rows();
18 if (m1.size() != m2_rows)
19 throw std::domain_error(
"m1 must have same length as m2 has rows");
20 int m2_cols = m2.cols();
21 Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R2, C2>
22 result(m2_rows,m2_cols);
23 for (
int j = 0; j < m2_cols; ++j)
24 for (
int i = 0; i < m2_rows; ++i)
25 result(i,j) = m1(i) * m2(i,j);
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)