| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
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 R2, C2>
14 diag_pre_multiply(const Eigen::Matrix<T1, R1, C1>& m1,
15 const Eigen::Matrix<T2, R2, C2>& m2) {
16 if (m1.cols() != 1 && m1.rows() != 1)
17 throw std::domain_error("m1 must be a vector");
18 int m2_rows = m2.rows();
19 if (m1.size() != m2_rows)
20 throw std::domain_error("m1 must have same length as m2 has rows");
21 int m2_cols = m2.cols();
22 Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
23 R2, C2>
24 result(m2_rows, m2_cols);
25 for (int j = 0; j < m2_cols; ++j)
26 for (int i = 0; i < m2_rows; ++i)
27 result(i, j) = m1(i) * m2(i, j);
28 return result;
29 }
30
31 }
32 }
33 #endif
stan::math::domain_error
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.
Definition: domain_error.hpp:32
Eigen.hpp
stan::math::diag_pre_multiply
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)
Definition: diag_pre_multiply.hpp:14

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