Stan Math Library: stan/math/fwd/mat/fun/divide.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/fwd/mat/fun/to_fvar.hpp>
7 #include <stan/math/fwd/mat/fun/typedefs.hpp>
8 #include <stan/math/prim/scal/meta/return_type.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
typedefs.hpp
core.hpp
stan::math::operator/
fvar< T > operator/(const fvar< T > &x1, const fvar< T > &x2)
Definition: operator_division.hpp:14
stan
Definition: log_sum_exp.hpp:8
return_type.hpp
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
to_fvar.hpp
stan::math::fvar
Definition: fvar.hpp:13

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