Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
elt_divide.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__ELT_DIVIDE_HPP
2 #define STAN__MATH__MATRIX__ELT_DIVIDE_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
7 
8 namespace stan {
9  namespace math {
10 
22  template <typename T1, typename T2, int R, int C>
23  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
24  elt_divide(const Eigen::Matrix<T1,R,C>& m1,
25  const Eigen::Matrix<T2,R,C>& m2) {
26  stan::math::check_matching_dims("elt_divide(%1%)",m1,"m1",
27  m2,"m2",(double*)0);
28  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
29  result(m1.rows(),m2.cols());
30  for (int i = 0; i < m1.size(); ++i)
31  result(i) = m1(i) / m2(i);
32  return result;
33  }
34 
47  template <typename T1, typename T2, int R, int C>
48  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
49  elt_divide(const Eigen::Matrix<T1,R,C>& m, T2 s){
50  return m / s;
51  }
52 
65  template <typename T1, typename T2, int R, int C>
66  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
67  elt_divide(T1 s,
68  const Eigen::Matrix<T2,R,C>& m) {
69  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
70  result(m.rows(),m.cols());
71  for (int i = 0; i < m.size(); ++i)
72  result(i) = s / m(i);
73  return result;
74  }
75 
76  }
77 }
78 #endif
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R, C > elt_divide(const Eigen::Matrix< T1, R, C > &m1, const Eigen::Matrix< T2, R, C > &m2)
Return the elementwise division of the specified matrices.
Definition: elt_divide.hpp:24
bool check_matching_dims(const char *function, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name1, const Eigen::Matrix< T2, R2, C2 > &y2, const char *name2, T_result *result)

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