Automatic Differentiation
 
Loading...
Searching...
No Matches
norm1.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_NORM1_HPP
2#define STAN_MATH_REV_FUN_NORM1_HPP
3
11
12namespace stan {
13namespace math {
14
23template <typename T, require_eigen_vector_vt<is_var, T>* = nullptr>
24inline var norm1(const T& v) {
25 arena_t<T> arena_v = v;
26 var res = norm1(arena_v.val());
27 reverse_pass_callback([res, arena_v]() mutable {
28 arena_v.adj().array() += res.adj() * sign(arena_v.val().array());
29 });
30 return res;
31}
32
40//
41template <typename T, require_var_matrix_t<T>* = nullptr>
42inline var norm1(const T& v) {
43 return make_callback_vari(norm1(v.val()), [v](const auto& res) mutable {
44 v.adj().array() += res.adj() * sign(v.val().array());
45 });
46}
47
48} // namespace math
49} // namespace stan
50#endif
auto sign(const T &x)
Returns signs of the arguments.
Definition sign.hpp:18
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
var_value< double > var
Definition var.hpp:1187
auto norm1(const Container &x)
Compute the L1 norm of the specified vector of values.
Definition norm1.hpp:23
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...