Stan Math Library  2.10.0
reverse mode automatic differentiation
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 T, int R, int C>
15  inline Eigen::Matrix<fvar<T>, R, C>
16  divide(const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
17  Eigen::Matrix<fvar<T>, R, C> res(v.rows(), v.cols());
18  for (int i = 0; i < v.rows(); i++) {
19  for (int j = 0; j < v.cols(); j++)
20  res(i, j) = v(i, j) / c;
21  }
22  return res;
23  }
24 
25  template <typename T, int R, int C>
26  inline Eigen::Matrix<fvar<T>, R, C>
27  divide(const Eigen::Matrix<fvar<T>, R, C>& v, const double c) {
28  Eigen::Matrix<fvar<T>, R, C>
29  res(v.rows(), v.cols());
30  for (int i = 0; i < v.rows(); i++) {
31  for (int j = 0; j < v.cols(); j++)
32  res(i, j) = v(i, j) / c;
33  }
34  return res;
35  }
36 
37  template <typename T, int R, int C>
38  inline Eigen::Matrix<fvar<T>, R, C>
39  divide(const Eigen::Matrix<double, R, C>& v, const fvar<T>& c) {
40  Eigen::Matrix<fvar<T>, R, C>
41  res(v.rows(), v.cols());
42  for (int i = 0; i < v.rows(); i++) {
43  for (int j = 0; j < v.cols(); j++)
44  res(i, j) = v(i, j) / c;
45  }
46  return res;
47  }
48 
49  template <typename T, int R, int C>
50  inline Eigen::Matrix<fvar<T>, R, C>
51  operator/(const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
52  return divide(v, c);
53  }
54 
55  template <typename T, int R, int C>
56  inline Eigen::Matrix<fvar<T>, R, C>
57  operator/(const Eigen::Matrix<fvar<T>, R, C>& v, const double c) {
58  return divide(v, c);
59  }
60 
61  template <typename T, int R, int C>
62  inline Eigen::Matrix<fvar<T>, R, C>
63  operator/(const Eigen::Matrix<double, R, C>& v, const fvar<T>& c) {
64  return divide(v, c);
65  }
66  }
67 }
68 #endif
fvar< T > operator/(const fvar< T > &x1, const fvar< T > &x2)
Eigen::Matrix< fvar< T >, R, C > divide(const Eigen::Matrix< fvar< T >, R, C > &v, const fvar< T > &c)
Definition: divide.hpp:16

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