1#ifndef STAN_MATH_FWD_FUNCTOR_FINITE_DIFF_HPP
2#define STAN_MATH_FWD_FUNCTOR_FINITE_DIFF_HPP
25template <
typename FuncTangent,
typename InputArg,
28 const InputArg&
arg) {
44template <
typename FuncTangent,
typename InputArg,
48 tangent,
arg, [](
const auto& x,
const auto& y) {
return x * y.d_; }));
67template <
typename F,
typename... TArgs,
71 using FvarInnerT =
typename FvarT::Scalar;
73 std::vector<FvarInnerT> serialised_args
74 = serialize<FvarInnerT>(
value_of(args)...);
76 auto serial_functor = [&](
const auto& v) {
78 return func(v_deserializer.read(args)...);
82 std::vector<FvarInnerT>
grad;
85 FvarInnerT rtn_grad = 0;
90 grad_deserializer.read(args), args),
93 return FvarT(rtn_value, rtn_grad);
111template <
typename F,
typename... TArgs,
113inline auto finite_diff(
const F& func,
const TArgs&... args) {
114 return func(args...);
require_all_not_t< is_fvar< scalar_type_t< std::decay_t< Types > > >... > require_all_not_st_fvar
Require none of the scalar types satisfy is_fvar.
require_any_t< is_fvar< scalar_type_t< std::decay_t< Types > > >... > require_any_st_fvar
Require any of the scalar types satisfy is_fvar.
require_t< is_fvar< scalar_type_t< std::decay_t< T > > > > require_st_fvar
Require scalar type satisfies is_fvar.
require_not_t< is_fvar< scalar_type_t< std::decay_t< T > > > > require_not_st_fvar
Require scalar type does not satisfy is_fvar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
constexpr double aggregate_tangent(const FuncTangent &tangent, const InputArg &arg)
Helper function for aggregating tangents if the respective input argument was an fvar<T> type.
void finite_diff_gradient_auto(const F &f, VectorT &&x, ScalarT &fx, GradVectorT &grad_fx)
Calculate the value and the gradient of the specified function at the specified argument using finite...
deserializer< T > to_deserializer(const std::vector< T > &vals)
Return a deserializer based on the specified values.
fvar< T > arg(const std::complex< fvar< T > > &z)
Return the phase angle of the complex argument.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
auto apply_scalar_binary(const T1 &x, const T2 &y, const F &f)
Base template function for vectorization of binary scalar functions defined by applying a functor to ...
auto finite_diff(const F &func, const TArgs &... args)
Construct an fvar<T> where the tangent is calculated by finite-differencing.
static void grad()
Compute the gradient for all variables starting from the end of the AD tape.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...