Stan Math Library  2.12.0
reverse mode automatic differentiation
elt_divide.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_ELT_DIVIDE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_ELT_DIVIDE_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
8 
9 namespace stan {
10  namespace math {
11 
23  template <typename T1, typename T2, int R, int C>
24  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
25  elt_divide(const Eigen::Matrix<T1, R, C>& m1,
26  const Eigen::Matrix<T2, R, C>& m2) {
27  check_matching_dims("elt_divide", "m1", m1, "m2", m2);
28  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
29  R, C> 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 divide(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,
70  R, C> 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
bool check_matching_dims(const char *function, const char *name1, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name2, const Eigen::Matrix< T2, R2, C2 > &y2)
Return true if the two matrices are of the same size.
Eigen::Matrix< fvar< T >, R, C > divide(const Eigen::Matrix< fvar< T >, R, C > &v, const fvar< T > &c)
Definition: divide.hpp:16
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:25

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