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
10#include <cmath>
11#include <complex>
12
13namespace stan {
14namespace math {
15
43inline var cos(var a) {
44 return make_callback_var(std::cos(a.val()), [a](const auto& vi) mutable {
45 a.adj() -= vi.adj() * std::sin(a.val());
46 });
47}
48
57template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr>
58inline auto cos(const VarMat& a) {
59 return make_callback_var(
60 a.val().array().cos().matrix(), [a](const auto& vi) mutable {
61 a.adj() -= vi.adj().cwiseProduct(a.val().array().sin().matrix());
62 });
63}
70inline std::complex<var> cos(const std::complex<var>& z) {
72}
73
74} // namespace math
75} // namespace stan
76#endif
std::complex< T > complex_cos(const std::complex< T > &z)
Return the cosine of the complex argument.
Definition cos.hpp:91
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:16
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...