Automatic Differentiation
 
Loading...
Searching...
No Matches
cbrt.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_CBRT_HPP
2#define STAN_MATH_REV_FUN_CBRT_HPP
3
7
8namespace stan {
9namespace math {
10
37inline var cbrt(const var& a) {
38 return make_callback_var(cbrt(a.val()), [a](const auto& vi) mutable {
39 a.adj() += vi.adj() / (3.0 * vi.val() * vi.val());
40 });
41}
42
49template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr>
50inline auto cbrt(const VarMat& a) {
51 return make_callback_var(
52 a.val().unaryExpr([](const auto x) { return cbrt(x); }),
53 [a](const auto& vi) mutable {
54 a.adj().array() += vi.adj().array() / (3.0 * vi.val().array().square());
55 });
56}
57
58} // namespace math
59} // namespace stan
60#endif
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...
fvar< T > cbrt(const fvar< T > &x)
Return cube root of specified argument.
Definition cbrt.hpp:20
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...