Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
stochastic_column_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_COLUMN_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_COLUMN_CONSTRAIN_HPP
3
11#include <cmath>
12
13namespace stan {
14namespace math {
15
25template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
26 require_not_st_var<Mat>* = nullptr>
28 auto&& y_ref = to_ref(y);
29 const Eigen::Index M = y_ref.cols();
30 plain_type_t<Mat> ret(y_ref.rows() + 1, M);
31 for (Eigen::Index i = 0; i < M; ++i) {
32 ret.col(i) = simplex_constrain(y_ref.col(i));
33 }
34 return ret;
35}
36
52template <typename Mat, typename Lp,
54 require_not_st_var<Mat>* = nullptr,
56inline plain_type_t<Mat> stochastic_column_constrain(const Mat& y, Lp& lp) {
57 auto&& y_ref = to_ref(y);
58 const Eigen::Index M = y_ref.cols();
59 plain_type_t<Mat> ret(y_ref.rows() + 1, M);
60 for (Eigen::Index i = 0; i < M; ++i) {
61 ret.col(i) = simplex_constrain(y_ref.col(i), lp);
62 }
63 return ret;
64}
76template <typename T, require_std_vector_t<T>* = nullptr>
77inline auto stochastic_column_constrain(const T& y) {
79 y, [](auto&& v) { return stochastic_column_constrain(v); });
80}
81
96template <typename T, typename Lp, require_std_vector_t<T>* = nullptr,
97 require_convertible_t<return_type_t<T>, Lp>* = nullptr>
98inline auto stochastic_column_constrain(const T& y, Lp& lp) {
100 y, [&lp](auto&& v) { return stochastic_column_constrain(v, lp); });
101}
102
121template <bool Jacobian, typename Mat, typename Lp,
123inline plain_type_t<Mat> stochastic_column_constrain(const Mat& y, Lp& lp) {
124 if constexpr (Jacobian) {
125 return stochastic_column_constrain(y, lp);
126 } else {
128 }
129}
130
131} // namespace math
132} // namespace stan
133
134#endif
require_t< std::is_convertible< std::decay_t< T >, std::decay_t< S > > > require_convertible_t
Require types T and S satisfies std::is_convertible.
require_t< is_eigen_matrix_dynamic< std::decay_t< T > > > require_eigen_matrix_dynamic_t
Require type satisfies is_eigen_matrix_dynamic.
require_not_t< is_var< scalar_type_t< std::decay_t< T > > > > require_not_st_var
Require scalar type does not satisfy is_var.
Definition is_var.hpp:117
plain_type_t< Mat > stochastic_column_constrain(const Mat &y)
Return a column stochastic matrix.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
plain_type_t< Vec > simplex_constrain(const Vec &y)
Return the simplex corresponding to the specified free vector.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...