Automatic Differentiation
 
Loading...
Searching...
No Matches
hypot.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_HYPOT_HPP
2#define STAN_MATH_REV_FUN_HYPOT_HPP
3
7
8namespace stan {
9namespace math {
10
27inline var hypot(const var& a, const var& b) {
28 return make_callback_var(hypot(a.val(), b.val()), [a, b](auto& vi) mutable {
29 a.adj() += vi.adj() * a.val() / vi.val();
30 b.adj() += vi.adj() * b.val() / vi.val();
31 });
32}
33
46inline var hypot(const var& a, double b) {
47 return make_callback_var(hypot(a.val(), b), [a](auto& vi) mutable {
48 a.adj() += vi.adj() * a.val() / vi.val();
49 });
50}
51
91inline var hypot(double a, const var& b) {
92 return make_callback_var(hypot(b.val(), a), [b](auto& vi) mutable {
93 b.adj() += vi.adj() * b.val() / vi.val();
94 });
95}
96
97} // namespace math
98} // namespace stan
99#endif
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Return the length of the hypotenuse of a right triangle with opposite and adjacent side lengths given...
Definition hypot.hpp:26
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...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...