Automatic Differentiation
 
Loading...
Searching...
No Matches
value_of_rec.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_VALUE_OF_REC_HPP
2#define STAN_MATH_PRIM_FUN_VALUE_OF_REC_HPP
3
6#include <complex>
7#include <cstddef>
8#include <vector>
9
10namespace stan {
11namespace math {
12
28template <typename T, typename = require_stan_scalar_t<T>>
29inline double value_of_rec(const T x) {
30 return static_cast<double>(x);
31}
32
44inline double value_of_rec(double x) { return x; }
45
53template <typename T>
54inline std::complex<double> value_of_rec(const std::complex<T>& x) {
55 return {value_of_rec(x.real()), value_of_rec(x.imag())};
56}
57
68template <typename T, require_not_same_t<double, T>* = nullptr>
69inline std::vector<double> value_of_rec(const std::vector<T>& x) {
70 size_t x_size = x.size();
71 std::vector<double> result(x_size);
72 for (size_t i = 0; i < x_size; i++) {
73 result[i] = value_of_rec(x[i]);
74 }
75 return result;
76}
77
89template <typename T, require_std_vector_t<T>* = nullptr,
90 require_vt_same<double, T>* = nullptr>
91inline T value_of_rec(T&& x) {
92 return std::forward<T>(x);
93}
94
105template <typename T, typename = require_not_st_same<T, double>,
106 typename = require_eigen_t<T>>
107inline auto value_of_rec(T&& M) {
108 return make_holder(
109 [](auto& m) {
110 return m.unaryExpr([](auto x) { return value_of_rec(x); });
111 },
112 std::forward<T>(M));
113}
114
127template <typename T, typename = require_st_same<T, double>,
128 typename = require_eigen_t<T>>
129inline T value_of_rec(T&& x) {
130 return std::forward<T>(x);
131}
132} // namespace math
133} // namespace stan
134
135#endif
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
auto make_holder(const F &func, Args &&... args)
Constructs an expression from given arguments using given functor.
Definition holder.hpp:352
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...