Automatic Differentiation
 
Loading...
Searching...
No Matches
tan.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_TAN_HPP
2#define STAN_MATH_REV_FUN_TAN_HPP
3
11#include <cmath>
12#include <complex>
13
14namespace stan {
15namespace math {
16
47inline var tan(const var& a) {
48 return make_callback_var(std::tan(a.val()), [a](const auto& vi) mutable {
49 a.adj() += vi.adj() * (1.0 + vi.val() * vi.val());
50 });
51}
52
61template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr>
62inline auto tan(const VarMat& a) {
63 return make_callback_var(a.val().array().tan().matrix(),
64 [a](const auto& vi) mutable {
65 a.adj() += vi.adj().cwiseProduct(
66 (1.0 + vi.val().array().square()).matrix());
67 });
68}
69
76inline std::complex<var> tan(const std::complex<var>& z) {
78}
79
80} // namespace math
81} // namespace stan
82#endif
std::complex< V > complex_tan(const std::complex< V > &z)
Return the tangent of the complex argument.
Definition tan.hpp:71
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 > tan(const fvar< T > &x)
Definition tan.hpp:14
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...