Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
add.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__ADD_HPP__
2 #define __STAN__MATH__MATRIX__ADD_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  add(const Eigen::Matrix<T1,R,C>& m1,
28  const Eigen::Matrix<T2,R,C>& m2) {
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 
46  template <typename T1, typename T2, int R, int C>
47  inline
48  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
49  add(const Eigen::Matrix<T1,R,C>& m,
50  const T2& c) {
51  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
52  result(m.rows(),m.cols());
53  for (int i = 0; i < result.size(); ++i)
54  result(i) = m(i) + c;
55  return result;
56  }
57 
67  template <typename T1, typename T2, int R, int C>
68  inline
69  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
70  add(const T1& c,
71  const Eigen::Matrix<T2,R,C>& m) {
72  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
73  result(m.rows(),m.cols());
74  for (int i = 0; i < result.size(); ++i)
75  result(i) = c + m(i);
76  return result;
77  }
78 
79  }
80 }
81 #endif

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