1#ifndef STAN_MATH_PRIM_FUN_SELECT_HPP
2#define STAN_MATH_PRIM_FUN_SELECT_HPP
23template <
typename T_true,
typename T_false,
24 typename ReturnT = return_type_t<T_true, T_false>,
25 require_all_stan_scalar_t<T_true, T_false>* =
nullptr>
26inline ReturnT
select(
const bool c,
const T_true y_true,
27 const T_false y_false) {
28 return c ? ReturnT(y_true) : ReturnT(y_false);
48 typename T_true,
typename T_false,
50 typename T_true_plain = promote_scalar_t<T_return, plain_type_t<T_true>>,
51 typename T_false_plain = promote_scalar_t<T_return, plain_type_t<T_false>>,
54inline T_true_plain
select(
const bool c, T_true&& y_true, T_false&& y_false) {
57 return c ? T_true_plain(std::forward<T_true>(y_true))
58 : T_true_plain(std::forward<T_false>(y_false));
78template <
typename T_true,
typename T_false,
79 typename ReturnT = promote_scalar_t<return_type_t<T_true, T_false>,
83inline ReturnT
select(
const bool c,
const T_true& y_true,
84 const T_false& y_false) {
90 [](
const auto& y_true_inner,
const auto& y_false_inner) {
113template <
typename T_true,
typename T_false,
114 typename ReturnT = promote_scalar_t<return_type_t<T_true, T_false>,
118inline ReturnT
select(
const bool c,
const T_true y_true,
119 const T_false y_false) {
123 [](
const auto& y_true_inner,
const auto& y_false_inner) {
146template <
typename T_bool,
typename T_true,
typename T_false,
149inline auto select(
const T_bool c,
const T_true y_true,
const T_false y_false) {
152 .unaryExpr([y_true, y_false](
bool cond) {
153 return cond ? ret_t(y_true) : ret_t(y_false);
170template <
typename T_bool,
typename T_true,
typename T_false,
173inline auto select(
const T_bool c,
const T_true y_true,
const T_false y_false) {
175 "right hand side", y_false);
177 return c.select(y_true, y_false).template cast<ret_t>().eval();
require_all_t< is_container< std::decay_t< Types > >... > require_all_container_t
Require all of the types satisfy is_container.
require_t< is_container< std::decay_t< T > > > require_container_t
Require type satisfies is_container.
require_any_t< is_eigen_array< std::decay_t< Types > >... > require_any_eigen_array_t
Require any of the types satisfy is_eigen_array.
require_t< container_type_check_base< is_eigen_array, value_type_t, TypeCheck, Check... > > require_eigen_array_vt
Require type satisfies is_eigen_array.
require_t< is_eigen_array< std::decay_t< T > > > require_eigen_array_t
Require type satisfies is_eigen_array.
select_< as_operation_cl_t< T_condition >, as_operation_cl_t< T_then >, as_operation_cl_t< T_else > > select(T_condition &&condition, T_then &&then, T_else &&els)
Selection operation on kernel generator expressions.
require_all_t< std::is_same< std::decay_t< T >, std::decay_t< Types > >... > require_all_same_t
Require T and all of the Types satisfy std::is_same.
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
void check_matching_dims(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the two containers have the same dimensions.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
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 ...
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...