All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
add.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_ADD_HPP
#define STAN_MATH_PRIM_MAT_FUN_ADD_HPP
#include <boost/math/tools/promotion.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
namespace stan {
namespace math {
template <typename T1, typename T2, int R, int C>
inline
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) {
stan::math::check_matching_dims("add",
"m1", m1,
"m2", m2);
Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
R, C>
result(m1.rows(), m1.cols());
for (int i = 0; i < result.size(); ++i)
result(i) = m1(i) + m2(i);
return result;
}
template <typename T1, typename T2, int R, int C>
inline
Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
add(const Eigen::Matrix<T1, R, C>& m,
const T2& c) {
Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
R, C>
result(m.rows(), m.cols());
for (int i = 0; i < result.size(); ++i)
result(i) = m(i) + c;
return result;
}
template <typename T1, typename T2, int R, int C>
inline
Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type, R, C>
add(const T1& c,
const Eigen::Matrix<T2, R, C>& m) {
Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
R, C>
result(m.rows(), m.cols());
for (int i = 0; i < result.size(); ++i)
result(i) = c + m(i);
return result;
}
}
}
#endif
check_matching_dims.hpp
stan::math::check_matching_dims
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.
Definition: check_matching_dims.hpp:37
Eigen.hpp
stan::math::add
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.