1#ifndef STAN_MATH_PRIM_CONSTRAINT_LUB_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_LUB_CONSTRAIN_HPP
44template <
typename T,
typename L,
typename U,
45 require_all_stan_scalar_t<T, L, U>* =
nullptr,
46 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
50 if (
unlikely(is_ub_inf && is_lb_inf)) {
95template <
typename T,
typename L,
typename U,
101 if (
unlikely(is_ub_inf && is_lb_inf)) {
109 const auto diff = ub - lb;
118template <
typename T,
typename L,
typename U, require_eigen_t<T>* =
nullptr,
119 require_all_stan_scalar_t<L, U>* =
nullptr,
120 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
123 x.unaryExpr([ub, lb](
auto&& xx) { return lub_constrain(xx, lb, ub); }));
129template <
typename T,
typename L,
typename U, require_eigen_t<T>* =
nullptr,
130 require_all_stan_scalar_t<L, U>* =
nullptr,
131 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
134 return eval(x.unaryExpr(
135 [lb, ub, &lp](
auto&& xx) { return lub_constrain(xx, lb, ub, lp); }));
142template <
typename T,
typename L,
typename U,
146inline auto lub_constrain(
const T& x,
const L& lb,
const U& ub) {
148 return eval(x.binaryExpr(
149 lb, [ub](
auto&& x,
auto&& lb) { return lub_constrain(x, lb, ub); }));
156template <
typename T,
typename L,
typename U,
157 require_all_eigen_t<T, L>* =
nullptr,
158 require_stan_scalar_t<U>* =
nullptr,
159 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
160inline auto lub_constrain(
const T& x,
const L& lb,
const U& ub,
161 return_type_t<T, L, U>& lp) {
163 return eval(x.binaryExpr(lb, [ub, &lp](
auto&& x,
auto&& lb) {
164 return lub_constrain(x, lb, ub, lp);
172template <
typename T,
typename L,
typename U,
173 require_all_eigen_t<T, U>* =
nullptr,
174 require_stan_scalar_t<L>* =
nullptr,
175 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
176inline auto lub_constrain(
const T& x,
const L& lb,
const U& ub) {
178 return eval(x.binaryExpr(
179 ub, [lb](
auto&& x,
auto&& ub) { return lub_constrain(x, lb, ub); }));
186template <
typename T,
typename L,
typename U,
187 require_all_eigen_t<T, U>* =
nullptr,
188 require_stan_scalar_t<L>* =
nullptr,
189 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
190inline auto lub_constrain(
const T& x,
const L& lb,
const U& ub,
191 return_type_t<T, L, U>& lp) {
193 return eval(x.binaryExpr(ub, [lb, &lp](
auto&& x,
auto&& ub) {
194 return lub_constrain(x, lb, ub, lp);
201template <
typename T,
typename L,
typename U,
202 require_all_eigen_t<T, L, U>* =
nullptr,
203 require_not_var_t<return_type_t<T, L, U>>* =
nullptr>
211 for (Eigen::Index j = 0; j < x_ref.cols(); ++j) {
212 for (Eigen::Index i = 0; i < x_ref.rows(); ++i) {
214 x_ref.coeff(i, j), lb_ref.coeff(i, j), ub_ref.coeff(i, j));
223template <
typename T,
typename L,
typename U,
226inline auto lub_constrain(
const T& x,
const L& lb,
const U& ub,
233 promote_scalar_t<return_type_t<T, L, U>, T> x_ret(x.rows(), x.cols());
234 for (Eigen::Index j = 0; j < x_ref.cols(); ++j) {
235 for (Eigen::Index i = 0; i < x_ref.rows(); ++i) {
237 x_ref.coeff(i, j), lb_ref.coeff(i, j), ub_ref.coeff(i, j), lp);
246template <
typename T,
typename L,
typename U,
247 require_all_not_std_vector_t<L, U>* =
nullptr>
248inline auto lub_constrain(
const std::vector<T>& x,
const L& lb,
const U& ub) {
251 for (
size_t i = 0; i < x.size(); ++i) {
260template <
typename T,
typename L,
typename U,
266 for (
size_t i = 0; i < x.size(); ++i) {
275template <
typename T,
typename L,
typename U,
278 const std::vector<U>& ub) {
282 for (
size_t i = 0; i < x.size(); ++i) {
291template <
typename T,
typename L,
typename U,
294 const std::vector<U>& ub,
299 for (
size_t i = 0; i < x.size(); ++i) {
308template <
typename T,
typename L,
typename U,
315 for (
size_t i = 0; i < x.size(); ++i) {
324template <
typename T,
typename L,
typename U,
331 for (
size_t i = 0; i < x.size(); ++i) {
340template <
typename T,
typename L,
typename U>
342 const std::vector<U>& ub) {
347 for (
size_t i = 0; i < x.size(); ++i) {
356template <
typename T,
typename L,
typename U>
358 const std::vector<U>& ub,
364 for (
size_t i = 0; i < x.size(); ++i) {
394template <
bool Jacobian,
typename T,
typename L,
typename U>
407template <
typename T,
typename L,
typename U>
409 return lub_constrain(x, std::get<0>(bounds), std::get<1>(bounds));
415template <
typename T,
typename L,
typename U>
418 return lub_constrain(x, std::get<0>(bounds), std::get<1>(bounds), lp);
424template <
bool Jacobian,
typename T,
typename L,
typename U>
427 return lub_constrain<Jacobian>(x, std::get<0>(bounds), std::get<1>(bounds),
require_all_t< is_eigen< std::decay_t< Types > >... > require_all_eigen_t
Require all of the types satisfy is_eigen.
subtraction_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > subtract(T_a &&a, T_b &&b)
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
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.
require_not_t< is_std_vector< std::decay_t< T > > > require_not_std_vector_t
Require type does not satisfy is_std_vector.
require_all_not_t< is_std_vector< std::decay_t< Types > >... > require_all_not_std_vector_t
Require none of the types satisfy is_std_vector.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_not_t< is_var< std::decay_t< T > > > require_not_var_t
Require type does not satisfy is_var.
fvar< T > abs(const fvar< T > &x)
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
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.
fvar< T > log1p_exp(const fvar< T > &x)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
auto lb_constrain(T &&x, L &&lb)
Return the lower-bounded value for the specified unconstrained input and specified lower bound.
auto ub_constrain(T &&x, U &&ub)
Return the upper-bounded value for the specified unconstrained matrix and upper bound.
matrix_cl< double > lub_constrain(const T &x, const L &lb, const U &ub)
Return the lower and upper-bounded matrix derived by transforming the specified free matrix given the...
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
auto identity_constrain(T &&x, Types &&...)
Returns the result of applying the identity constraint transform to the input.
static constexpr double INFTY
Positive infinity.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...