Automatic Differentiation
 
Loading...
Searching...
No Matches
ub_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_UB_CONSTRAIN_HPP
2#define STAN_MATH_OPENCL_PRIM_UB_CONSTRAIN_HPP
3#ifdef STAN_OPENCL
4
9
10namespace stan {
11namespace math {
12
29template <typename T, typename U,
30 require_all_kernel_expressions_and_none_scalar_t<T>* = nullptr,
31 require_all_kernel_expressions_t<U>* = nullptr>
32inline auto ub_constrain(T&& x, U&& ub) {
33 return make_holder_cl(
34 [](auto& x_, auto& ub_) {
35 return select(ub_ == INFTY, x_, ub_ - exp(x_));
36 },
37 std::forward<T>(x), std::forward<U>(ub));
38}
39
57template <typename T, typename U,
60inline auto ub_constrain(const T& x, const U& ub, return_type_t<T, U>& lp) {
61 matrix_cl<double> lp_inc;
63 auto ub_inf = ub == INFTY;
64 auto lp_inc_expr = sum_2d(select(ub_inf, 0.0, x));
65 auto res_expr = select(ub_inf, x, ub - exp(x));
66 results(lp_inc, res) = expressions(lp_inc_expr, res_expr);
67 lp += sum(from_matrix_cl(lp_inc));
68 return res;
69}
70
71} // namespace math
72} // namespace stan
73#endif
74#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
auto sum_2d(T &&a)
Two dimensional sum - reduction of a kernel generator expression.
auto make_holder_cl(const T &func, Args &&... args)
Constructs an expression from given arguments using given functor.
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.
Definition select.hpp:148
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
require_all_t< is_kernel_expression< Types >... > require_all_kernel_expressions_t
Enables a template if all given types are are a valid kernel generator expressions.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
require_all_t< is_kernel_expression_and_not_scalar< Types >... > require_all_kernel_expressions_and_none_scalar_t
Enables a template if all given types are non-scalar types that are a valid kernel generator expressi...
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
Definition copy.hpp:61
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:22
auto ub_constrain(T &&x, U &&ub)
Return the upper-bounded value for the specified unconstrained matrix and upper bound.
static constexpr double INFTY
Positive infinity.
Definition constants.hpp:46
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9