1#ifndef STAN_MATH_REV_CORE_OPERATOR_ADDITION_HPP
2#define STAN_MATH_REV_CORE_OPERATOR_ADDITION_HPP
55 [avi = a.vi_, bvi = b.vi_](
const auto& vi)
mutable {
73template <
typename Arith, require_arithmetic_t<Arith>* =
nullptr>
80 [avi = a.vi_](
const auto& vi)
mutable { avi->adj_ += vi.adj_; });
95template <
typename Arith, require_arithmetic_t<Arith>* =
nullptr>
109template <
typename VarMat1,
typename VarMat2,
111inline auto add(VarMat1&& a, VarMat2&& b) {
113 using op_ret_type =
decltype(a.val() + b.val());
119 for (Eigen::Index j = 0; j < ret.cols(); ++j) {
120 for (Eigen::Index i = 0; i < ret.rows(); ++i) {
121 const auto ref_adj = ret.adj().coeffRef(i, j);
122 arena_a.adj().coeffRef(i, j) += ref_adj;
123 arena_b.adj().coeffRef(i, j) += ref_adj;
139template <
typename Arith,
typename VarMat,
142inline auto add(VarMat&& a,
const Arith& b) {
152 [ret, arena_a]()
mutable { arena_a.adj() += ret.adj_op(); });
165template <
typename Arith,
typename VarMat,
168inline auto add(
const Arith& a, VarMat&& b) {
169 return add(std::forward<VarMat>(b), a);
181template <
typename Var,
typename EigMat,
184inline auto add(
const Var& a,
const EigMat& b) {
200template <
typename EigMat,
typename Var,
203inline auto add(
const EigMat& a,
const Var& b) {
217template <
typename Var,
typename VarMat,
220inline auto add(
const Var& a, VarMat&& b) {
225 for (Eigen::Index j = 0; j < ret.cols(); ++j) {
226 for (Eigen::Index i = 0; i < ret.rows(); ++i) {
227 const auto ret_adj = ret.adj().coeffRef(i, j);
229 arena_b.adj().coeffRef(i, j) += ret_adj;
246template <
typename Var,
typename VarMat,
249inline auto add(VarMat&& a,
const Var& b) {
250 return add(b, std::forward<VarMat>(a));
253template <
typename T1,
typename T2,
256inline auto add(
const T1& a,
const T2& b) {
260template <
typename T1,
typename T2,
262inline auto add(
const T1& a,
const T2& b) {
275template <
typename VarMat1,
typename VarMat2,
278 return add(std::forward<VarMat1>(a), std::forward<VarMat2>(b));
require_any_t< std::is_arithmetic< std::decay_t< Types > >... > require_any_arithmetic_t
Require any of the types satisfy std::is_arithmetic.
require_t< std::is_arithmetic< scalar_type_t< std::decay_t< T > > > > require_st_arithmetic
Require scalar type satisfies std::is_arithmetic.
require_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check... > > require_eigen_vt
Require type satisfies is_eigen.
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
require_t< is_rev_matrix< std::decay_t< T > > > require_rev_matrix_t
Require type satisfies is_rev_matrix.
require_all_t< is_rev_matrix< std::decay_t< Types > >... > require_all_rev_matrix_t
Require all of the types satisfy is_rev_matrix.
require_any_t< is_var_matrix< std::decay_t< Types > >... > require_any_var_matrix_t
Require any of the types satisfy is_var_matrix.
require_t< container_type_check_base< is_var, value_type_t, TypeCheck, Check... > > require_var_vt
Require type satisfies is_var.
require_any_t< container_type_check_base< is_var, value_type_t, TypeCheck, Check >... > require_any_var_vt
Require any of the types satisfy is_var.
require_all_t< container_type_check_base< is_var, value_type_t, TypeCheck, Check >... > require_all_var_vt
Require all of the types satisfy is_var.
T as_array_or_scalar(T &&v)
Returns specified input value.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
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.
fvar< T > operator+(const fvar< T > &x1, const fvar< T > &x2)
Return the sum of the specified forward mode addends.
internal::callback_vari< plain_type_t< T >, F > * make_callback_vari(T &&value, F &&functor)
Creates a new vari with given value and a callback that implements the reverse pass (chain).
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
std::conditional_t< is_any_var_matrix< ReturnType, Types... >::value, stan::math::var_value< stan::math::promote_scalar_t< double, plain_type_t< ReturnType > > >, stan::math::promote_scalar_t< stan::math::var_value< double >, plain_type_t< ReturnType > > > return_var_matrix_t
Given an Eigen type and several inputs, determine if a matrix should be var<Matrix> or Matrix<var>.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if type derives from EigenBase