1 #ifndef STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP 2 #define STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP 3 4 #include <stan/math/fwd/core.hpp> 5 #include <stan/math/prim/fun/Eigen.hpp> 6 #include <stan/math/rev/core.hpp> 7 #include <vector> 8 9 namespace stan { 10 namespace math { 11 12 /** 13 * Return the derivative of the specified univariate function at 14 * the specified argument. 15 * 16 * @tparam T Argument type 17 * @tparam F Function type 18 * @param[in] f Function 19 * @param[in] x Argument 20 * @param[out] fx Value of function applied to argument 21 * @param[out] dfx_dx Value of derivative 22 */ 23 template <typename T, typename F> derivative(const F & f,const T & x,T & fx,T & dfx_dx)24void derivative(const F& f, const T& x, T& fx, T& dfx_dx) { 25 fvar<T> x_fvar = fvar<T>(x, 1.0); 26 fvar<T> fx_fvar = f(x_fvar); 27 fx = fx_fvar.val_; 28 dfx_dx = fx_fvar.d_; 29 } 30 31 } // namespace math 32 } // namespace stan 33 #endif 34