Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
divide.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_DIVIDE_HPP
2 #define STAN_MATH_FWD_MAT_FUN_DIVIDE_HPP
3 
5 #include <stan/math/fwd/core.hpp>
9 #include <vector>
10 
11 namespace stan {
12  namespace math {
13 
14  template <typename T1, typename T2>
15  inline
17  divide(const T1& v, const T2& c) {
18  return v / c;
19  }
20 
21  template <typename T, int R, int C>
22  inline Eigen::Matrix<fvar<T>, R, C>
23  divide(const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
24  Eigen::Matrix<fvar<T>, R, C> res(v.rows(), v.cols());
25  for (int i = 0; i < v.rows(); i++) {
26  for (int j = 0; j < v.cols(); j++)
27  res(i, j) = v(i, j) / c;
28  }
29  return res;
30  }
31 
32  template <typename T, int R, int C>
33  inline Eigen::Matrix<fvar<T>, R, C>
34  divide(const Eigen::Matrix<fvar<T>, R, C>& v, const double c) {
35  Eigen::Matrix<fvar<T>, R, C>
36  res(v.rows(), v.cols());
37  for (int i = 0; i < v.rows(); i++) {
38  for (int j = 0; j < v.cols(); j++)
39  res(i, j) = v(i, j) / c;
40  }
41  return res;
42  }
43 
44  template <typename T, int R, int C>
45  inline Eigen::Matrix<fvar<T>, R, C>
46  divide(const Eigen::Matrix<double, R, C>& v, const fvar<T>& c) {
47  Eigen::Matrix<fvar<T>, R, C>
48  res(v.rows(), v.cols());
49  for (int i = 0; i < v.rows(); i++) {
50  for (int j = 0; j < v.cols(); j++)
51  res(i, j) = v(i, j) / c;
52  }
53  return res;
54  }
55 
56  template <typename T, int R, int C>
57  inline Eigen::Matrix<fvar<T>, R, C>
58  operator/(const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
59  return divide(v, c);
60  }
61 
62  template <typename T, int R, int C>
63  inline Eigen::Matrix<fvar<T>, R, C>
64  operator/(const Eigen::Matrix<fvar<T>, R, C>& v, const double c) {
65  return divide(v, c);
66  }
67 
68  template <typename T, int R, int C>
69  inline Eigen::Matrix<fvar<T>, R, C>
70  operator/(const Eigen::Matrix<double, R, C>& v, const fvar<T>& c) {
71  return divide(v, c);
72  }
73  }
74 }
75 #endif
fvar< T > operator/(const fvar< T > &x1, const fvar< T > &x2)
stan::return_type< T1, T2 >::type divide(const T1 &v, const T2 &c)
Definition: divide.hpp:17
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type
Definition: return_type.hpp:27

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