Automatic Differentiation
 
Loading...
Searching...
No Matches
offset_multiplier_free.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_OFFSET_MULTIPLIER_FREE_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_OFFSET_MULTIPLIER_FREE_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
13
41template <typename T, typename M, typename S>
42inline auto offset_multiplier_free(const T& y, const M& mu, const S& sigma) {
43 auto&& mu_ref = to_ref(mu);
44 auto&& sigma_ref = to_ref(sigma);
46 check_matching_dims("offset_multiplier_constrain", "y", y, "mu", mu);
47 }
49 check_matching_dims("offset_multiplier_constrain", "y", y, "sigma", sigma);
51 check_matching_dims("offset_multiplier_constrain", "mu", mu, "sigma",
52 sigma);
53 }
54
55 check_finite("offset_multiplier_constrain", "offset", value_of(mu_ref));
56 check_positive_finite("offset_multiplier_constrain", "multiplier",
57 value_of(sigma_ref));
58 return divide(subtract(y, mu_ref), sigma_ref);
59}
60
64template <typename T, typename M, typename S,
66inline auto offset_multiplier_free(const std::vector<T>& x, const M& mu,
67 const S& sigma) {
68 std::vector<plain_type_t<decltype(offset_multiplier_free(x[0], mu, sigma))>>
69 ret;
70 ret.reserve(x.size());
71 const auto& mu_ref = to_ref(mu);
72 const auto& sigma_ref = to_ref(sigma);
73 for (size_t i = 0; i < x.size(); ++i) {
74 ret.emplace_back(offset_multiplier_free(x[i], mu_ref, sigma_ref));
75 }
76 return ret;
77}
78
82template <typename T, typename M, typename S,
84inline auto offset_multiplier_free(const std::vector<T>& x, const M& mu,
85 const std::vector<S>& sigma) {
86 check_matching_dims("offset_multiplier_free", "x", x, "sigma", sigma);
87 std::vector<
88 plain_type_t<decltype(offset_multiplier_free(x[0], mu, sigma[0]))>>
89 ret;
90 ret.reserve(x.size());
91 const auto& mu_ref = to_ref(mu);
92 for (size_t i = 0; i < x.size(); ++i) {
93 ret.emplace_back(offset_multiplier_free(x[i], mu_ref, sigma[i]));
94 }
95 return ret;
96}
97
101template <typename T, typename M, typename S,
103inline auto offset_multiplier_free(const std::vector<T>& x,
104 const std::vector<M>& mu, const S& sigma) {
105 check_matching_dims("offset_multiplier_free", "x", x, "mu", mu);
106 std::vector<
107 plain_type_t<decltype(offset_multiplier_free(x[0], mu[0], sigma))>>
108 ret;
109 ret.reserve(x.size());
110 const auto& sigma_ref = to_ref(sigma);
111 for (size_t i = 0; i < x.size(); ++i) {
112 ret.emplace_back(offset_multiplier_free(x[i], mu[i], sigma_ref));
113 }
114 return ret;
115}
116
120template <typename T, typename M, typename S>
121inline auto offset_multiplier_free(const std::vector<T>& x,
122 const std::vector<M>& mu,
123 const std::vector<S>& sigma) {
124 check_matching_dims("offset_multiplier_free", "x", x, "mu", mu);
125 check_matching_dims("offset_multiplier_free", "x", x, "sigma", sigma);
126 std::vector<
127 plain_type_t<decltype(offset_multiplier_free(x[0], mu[0], sigma[0]))>>
128 ret;
129 ret.reserve(x.size());
130 for (size_t i = 0; i < x.size(); ++i) {
131 ret.emplace_back(offset_multiplier_free(x[i], mu[i], sigma[i]));
132 }
133 return ret;
134}
135
136} // namespace math
137} // namespace stan
138#endif
subtraction_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > subtract(T_a &&a, T_b &&b)
auto divide(T_a &&a, double d)
Returns the elementwise division of the kernel generator expression.
Definition divide.hpp:20
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.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
auto offset_multiplier_free(const T &y, const M &mu, const S &sigma)
Return the unconstrained variable that transforms to the specified offset and multiplier constrained ...
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.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if a type is derived from Eigen::EigenBase or is a var_value whose value_type is derived from E...
Definition is_matrix.hpp:18