Automatic Differentiation
 
Loading...
Searching...
No Matches
apply_scalar_unary.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_APPLY_SCALAR_UNARY_HPP
2#define STAN_MATH_PRIM_FUNCTOR_APPLY_SCALAR_UNARY_HPP
3
12#include <utility>
13#include <vector>
14
15namespace stan {
16namespace math {
17
41template <typename F, typename T, typename Enable = void>
43
52template <typename F, typename T>
62 template <typename TT>
63 static inline auto apply(TT&& x) {
64 return make_holder(
65 [](auto&& xx) {
66 return std::forward<decltype(xx)>(xx).unaryExpr([](auto&& xxx) {
67 return apply_scalar_unary<F, decltype(xxx)>::apply(
68 std::forward<decltype(xxx)>(xxx));
69 });
70 },
71 std::forward<TT>(x));
72 }
73
78 using return_t = std::decay_t<decltype(
79 apply_scalar_unary<F, T>::apply(std::declval<T>()))>;
80};
81
88template <typename F, typename T>
94 = std::decay_t<decltype(F::fun(std::declval<std::decay_t<T>>()))>;
95
105 template <typename T2>
106 static inline auto apply(T2 x) {
107 return F::fun(x);
108 }
109};
110
117template <typename F, typename T>
128 template <typename T2>
129 static inline auto apply(T2&& x) {
130 return F::fun(std::forward<T2>(x));
131 }
136 = std::decay_t<decltype(F::fun(std::declval<std::decay_t<T>>()))>;
137};
138
147template <typename F, typename T>
158 template <typename T2>
159 static inline auto apply(T2 x) {
160 return F::fun(x);
161 }
165 using return_t = std::decay_t<decltype(F::fun(std::declval<double>()))>;
166};
167
177template <typename F, typename T>
183 using return_t = typename std::vector<plain_type_t<
185
195 template <typename TT>
196 static inline auto apply(TT&& x) {
197 return_t fx(x.size());
198 for (size_t i = 0; i < x.size(); ++i) {
199 if constexpr (std::is_rvalue_reference_v<TT&&>) {
200 fx[i] = apply_scalar_unary<F, value_type_t<TT>>::apply(std::move(x[i]));
201 } else {
203 }
204 }
205 return fx;
206 }
207};
208
209} // namespace math
210} // namespace stan
211#endif
require_t< is_complex< std::decay_t< T > > > require_complex_t
Require type satisfies is_complex.
require_t< is_eigen< std::decay_t< T > > > require_eigen_t
Require type satisfies is_eigen.
Definition is_eigen.hpp:113
require_t< std::is_floating_point< std::decay_t< T > > > require_floating_point_t
Require type satisfies std::is_floating_point.
require_t< std::is_integral< std::decay_t< T > > > require_integral_t
Require type satisfies std::is_integral.
require_t< is_std_vector< std::decay_t< T > > > require_std_vector_t
Require type satisfies is_std_vector.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:437
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
Definition apply.hpp:51
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
static auto apply(T2 &&x)
Apply the function specified by F to the specified argument.
std::decay_t< decltype(F::fun(std::declval< std::decay_t< T > >()))> return_t
The return type.
static auto apply(TT &&x)
Return the result of applying the function defined by the template parameter F to the specified matri...
std::decay_t< decltype(apply_scalar_unary< F, T >::apply(std::declval< T >()))> return_t
Return type for applying the function elementwise to a matrix expression template of type T.
static auto apply(T2 x)
Apply the function specified by F to the specified argument.
std::decay_t< decltype(F::fun(std::declval< std::decay_t< T > >()))> return_t
The return type, double.
static auto apply(T2 x)
Apply the function specified by F to the specified argument.
std::decay_t< decltype(F::fun(std::declval< double >()))> return_t
The return type, double.
static auto apply(TT &&x)
Apply the function specified by F elementwise to the specified argument.
typename std::vector< plain_type_t< typename apply_scalar_unary< F, value_type_t< std::decay_t< T > > >::return_t > > return_t
Return type, which is calculated recursively as a standard vector of the return type of the contained...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...