Stan Math Library  2.10.0
reverse mode automatic differentiation
subtract.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_SUBTRACT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SUBTRACT_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
7 
8 namespace stan {
9  namespace math {
10 
24  template <typename T1, typename T2, int R, int C>
25  inline
26  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
27  subtract(const Eigen::Matrix<T1, R, C>& m1,
28  const Eigen::Matrix<T2, R, C>& m2) {
30  "m1", m1,
31  "m2", m2);
32  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
33  R, C>
34  result(m1.rows(), m1.cols());
35  for (int i = 0; i < result.size(); ++i)
36  result(i) = m1(i) - m2(i);
37  return result;
38  }
39 
40  template <typename T1, typename T2, int R, int C>
41  inline
42  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
43  subtract(const T1& c,
44  const Eigen::Matrix<T2, R, C>& m) {
45  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
46  R, C>
47  result(m.rows(), m.cols());
48  for (int i = 0; i < m.size(); ++i)
49  result(i) = c - m(i);
50  return result;
51  }
52 
53  template <typename T1, typename T2, int R, int C>
54  inline
55  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
56  subtract(const Eigen::Matrix<T1, R, C>& m,
57  const T2& c) {
58  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
59  R, C>
60  result(m.rows(), m.cols());
61  for (int i = 0; i < m.size(); ++i)
62  result(i) = m(i) - c;
63  return result;
64  }
65 
66  }
67 }
68 #endif
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R, C > subtract(const Eigen::Matrix< T1, R, C > &m1, const Eigen::Matrix< T2, R, C > &m2)
Return the result of subtracting the second specified matrix from the first specified matrix...
Definition: subtract.hpp:27
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.

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