Automatic Differentiation
 
Loading...
Searching...
No Matches
add.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_ADD_HPP
2#define STAN_MATH_PRIM_FUN_ADD_HPP
3
7
8namespace stan {
9namespace math {
10
20template <typename ScalarA, typename ScalarB,
21 require_all_stan_scalar_t<ScalarA, ScalarB>* = nullptr,
22 require_all_not_var_t<ScalarA, ScalarB>* = nullptr>
23inline return_type_t<ScalarA, ScalarB> add(const ScalarA& a, const ScalarB& b) {
24 return a + b;
25}
26
40template <typename Mat1, typename Mat2,
43inline auto add(Mat1&& m1, Mat2&& m2) {
44 check_matching_dims("add", "m1", m1, "m2", m2);
45 return make_holder([](auto&& m1_, auto&& m2_) { return m1_ + m2_; },
46 std::forward<Mat1>(m1), std::forward<Mat2>(m2));
47}
48
58template <typename Mat, typename Scal, require_eigen_t<Mat>* = nullptr,
59 require_stan_scalar_t<Scal>* = nullptr,
60 require_all_not_st_var<Mat, Scal>* = nullptr>
61inline auto add(Mat&& m, const Scal c) {
62 return make_holder([c](auto&& m_) { return (m_.array() + c).matrix(); },
63 std::forward<Mat>(m));
64}
65
75template <typename Scal, typename Mat, require_stan_scalar_t<Scal>* = nullptr,
76 require_eigen_t<Mat>* = nullptr,
77 require_all_not_st_var<Scal, Mat>* = nullptr>
78inline auto add(const Scal c, Mat&& m) {
79 return make_holder([c](auto&& m_) { return (c + m_.array()).matrix(); },
80 std::forward<Mat>(m));
81}
82
83} // namespace math
84} // namespace stan
85
86#endif
require_all_t< is_eigen< std::decay_t< Types > >... > require_all_eigen_t
Require all of the types satisfy is_eigen.
Definition is_eigen.hpp:123
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_all_not_t< is_var< scalar_type_t< std::decay_t< Types > > >... > require_all_not_st_var
Require none of the scalar types satisfy is_var.
Definition is_var.hpp:203
void check_matching_dims(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the two containers have the same dimensions.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:481
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...