Automatic Differentiation
 
Loading...
Searching...
No Matches
cos.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_COS_HPP
2#define STAN_MATH_REV_FUN_COS_HPP
3
13#include <cmath>
14#include <complex>
15
16namespace stan {
17namespace math {
18
46inline var cos(var a) {
47 return make_callback_var(std::cos(a.val()), [a](const auto& vi) mutable {
48 a.adj() -= vi.adj() * std::sin(a.val());
49 });
50}
51
60template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr>
61inline auto cos(const VarMat& a) {
62 return make_callback_var(
63 a.val().array().cos().matrix(), [a](const auto& vi) mutable {
64 a.adj() -= vi.adj().cwiseProduct(a.val().array().sin().matrix());
65 });
66}
73inline std::complex<var> cos(const std::complex<var>& z) {
75}
76
77} // namespace math
78} // namespace stan
79#endif
std::complex< T > complex_cos(const std::complex< T > &z)
Return the cosine of the complex argument.
Definition cos.hpp:72
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 > cos(const fvar< T > &x)
Definition cos.hpp:14
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...