Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
subtract.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__SUBTRACT_HPP__
2 #define __STAN__MATH__MATRIX__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) {
29  stan::math::validate_matching_dims(m1,m2,"subtract");
30  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
31  result(m1.rows(), m1.cols());
32  for (int i = 0; i < result.size(); ++i)
33  result(i) = m1(i) - m2(i);
34  return result;
35  }
36 
37  template <typename T1, typename T2, int R, int C>
38  inline
39  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
40  subtract(const T1& c,
41  const Eigen::Matrix<T2,R,C>& m) {
42  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
43  result(m.rows(),m.cols());
44  for (int i = 0; i < m.size(); ++i)
45  result(i) = c - m(i);
46  return result;
47  }
48 
49  template <typename T1, typename T2, int R, int C>
50  inline
51  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
52  subtract(const Eigen::Matrix<T1,R,C>& m,
53  const T2& c) {
54  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
55  result(m.rows(),m.cols());
56  for (int i = 0; i < m.size(); ++i)
57  result(i) = m(i) - c;
58  return result;
59  }
60 
61  }
62 }
63 #endif

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