| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/prim/mat/fun/divide.hpp>
7 #include <stan/math/prim/mat/err/check_matching_dims.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 stan::math::check_matching_dims("elt_divide",
28 "m1", m1,
29 "m2", m2);
30 Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
31 R, C> result(m1.rows(), m2.cols());
32 for (int i = 0; i < m1.size(); ++i)
33 result(i) = m1(i) / m2(i);
34 return result;
35 }
36
49 template <typename T1, typename T2, int R, int C>
50 Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
51 elt_divide(const Eigen::Matrix<T1, R, C>& m, T2 s) {
52 return divide(m, s); // TODO(carp): stan::math::divide(m, s);
53 }
54
67 template <typename T1, typename T2, int R, int C>
68 Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
69 elt_divide(T1 s,
70 const Eigen::Matrix<T2, R, C>& m) {
71 Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
72 R, C> result(m.rows(), m.cols());
73 for (int i = 0; i < m.size(); ++i)
74 result(i) = s / m(i);
75 return result;
76 }
77
78 }
79 }
80 #endif
check_matching_dims.hpp
stan
Definition: log_sum_exp.hpp:8
divide.hpp
stan::math::check_matching_dims
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.
Definition: check_matching_dims.hpp:37
stan::math::divide
Eigen::Matrix< fvar< T >, R, C > divide(const Eigen::Matrix< fvar< T >, R, C > &v, const fvar< T > &c)
Definition: divide.hpp:16
Eigen.hpp
stan::math::elt_divide
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.