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 Container,
24 require_eigen_vector_vt<is_var, Container>* = nullptr>
25inline var norm1(Container&& x) {
26 arena_t<Container> arena_x = std::forward<Container>(x);
27 var res = norm1(arena_x.val());
28 reverse_pass_callback([res, arena_x]() mutable {
29 arena_x.adj().array() += res.adj() * sign(arena_x.val().array());
30 });
31 return res;
32}
33
41//
42template <typename Container, require_var_matrix_t<Container>* = nullptr>
43inline var norm1(const Container& x) {
44 return make_callback_vari(norm1(x.val()), [x](const auto& res) mutable {
45 x.adj().array() += res.adj() * sign(x.val().array());
46 });
47}
48
49} // namespace math
50} // namespace stan
51#endif
auto norm1(Container &&x)
Compute the L1 norm of the specified vector of values.
Definition norm1.hpp:23
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.
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 ...