Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
diag_pre_multiply.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__DIAG_PRE_MULTIPLY_HPP__
2 #define __STAN__MATH__MATRIX__DIAG_PRE_MULTIPLY_HPP__
3 
4 #include <stdexcept>
5 #include <boost/math/tools/promotion.hpp>
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, R2, C2>
13  diag_pre_multiply(const Eigen::Matrix<T1,R1,C1>& m1,
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  if (m1.size() != m2.rows())
18  throw std::domain_error("m1 must have same length as m2 has rows");
19  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R2, C2>
20  result(m2.rows(),m2.cols());
21  for (int i = 0; i < m2.rows(); ++i)
22  for (int j = 0; i < m2.cols(); ++j)
23  result(i,j) = m1(i) * m2(i,j);
24  return result;
25  }
26 
27  }
28 }
29 #endif

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