Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations 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) {
29  stan::math::check_matching_dims("add(%1%)",m1,"m1",
30  m2,"m2",(double*)0);
31  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
32  result(m1.rows(),m1.cols());
33  for (int i = 0; i < result.size(); ++i)
34  result(i) = m1(i) + m2(i);
35  return result;
36  }
37 
47  template <typename T1, typename T2, int R, int C>
48  inline
49  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
50  add(const Eigen::Matrix<T1,R,C>& m,
51  const T2& c) {
52  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
53  result(m.rows(),m.cols());
54  for (int i = 0; i < result.size(); ++i)
55  result(i) = m(i) + c;
56  return result;
57  }
58 
68  template <typename T1, typename T2, int R, int C>
69  inline
70  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
71  add(const T1& c,
72  const Eigen::Matrix<T2,R,C>& m) {
73  Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
74  result(m.rows(),m.cols());
75  for (int i = 0; i < result.size(); ++i)
76  result(i) = c + m(i);
77  return result;
78  }
79 
80  }
81 }
82 #endif
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R, C > add(const Eigen::Matrix< T1, R, C > &m1, const Eigen::Matrix< T2, R, C > &m2)
Return the sum of the specified matrices.
Definition: add.hpp:27
bool check_matching_dims(const char *function, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name1, const Eigen::Matrix< T2, R2, C2 > &y2, const char *name2, T_result *result)

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