Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
add.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_ADD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_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  "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 
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  add(const Eigen::Matrix<T1, R, C>& m,
53  const T2& c) {
54  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
55  R, C>
56  result(m.rows(), m.cols());
57  for (int i = 0; i < result.size(); ++i)
58  result(i) = m(i) + c;
59  return result;
60  }
61 
71  template <typename T1, typename T2, int R, int C>
72  inline
73  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
74  add(const T1& c,
75  const Eigen::Matrix<T2, R, C>& m) {
76  Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
77  R, C>
78  result(m.rows(), m.cols());
79  for (int i = 0; i < result.size(); ++i)
80  result(i) = c + m(i);
81  return result;
82  }
83 
84  }
85 }
86 #endif
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.
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

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