1#ifndef STAN_MATH_REV_FUN_FABS_HPP
2#define STAN_MATH_REV_FUN_FABS_HPP
53 }
else if (a.val() < 0.0) {
55 }
else if (a.val() == 0) {
70template <
typename VarMat, require_var_matrix_t<VarMat>* =
nullptr>
71inline auto fabs(
const VarMat& a) {
73 a.val().unaryExpr([](
const auto x) {
74 if (unlikely(is_nan(x))) {
80 [a](
const auto& vi)
mutable {
81 for (Eigen::Index j = 0; j < vi.cols(); ++j) {
82 for (Eigen::Index i = 0; i < vi.rows(); ++i) {
83 const auto x = a.val().coeffRef(i, j);
87 a.adj().coeffRef(i, j) -= vi.adj_.coeff(i, j);
89 a.adj().coeffRef(i, j) += vi.adj_.coeff(i, j);
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
vari_value< double > vari
fvar< T > fabs(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...