Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
divide.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__MATRIX__DIVIDE_HPP
2 #define STAN__AGRAD__FWD__MATRIX__DIVIDE_HPP
3 
4 #include <vector>
6 #include <stan/agrad/fwd.hpp>
10 
11 namespace stan {
12  namespace agrad {
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
Eigen::Matrix< fvar< T >, R, C > operator/(const Eigen::Matrix< fvar< T >, R, C > &v, const fvar< T > &c)
Definition: divide.hpp:58
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: traits.hpp:406
stan::return_type< T1, T2 >::type divide(const T1 &v, const T2 &c)
Definition: divide.hpp:17

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