Automatic Differentiation
 
Loading...
Searching...
No Matches
std_normal_lpdf.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_STD_NORMAL_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_STD_NORMAL_LPDF_HPP
3
12
13namespace stan {
14namespace math {
15
29template <
30 bool propto, typename T_y,
31 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<T_y>* = nullptr>
33 using T_partials_return = partials_return_t<T_y>;
34 using T_y_ref = ref_type_t<T_y>;
35 static constexpr const char* function = "std_normal_lpdf";
36 T_y_ref y_ref = y;
37 check_not_nan(function, "Random variable", y_ref);
38
39 if (size_zero(y)) {
40 return 0.0;
41 }
43 return 0.0;
44 }
45
46 T_partials_return logp(0.0);
47 auto ops_partials = make_partials_propagator(y_ref);
48
49 scalar_seq_view<T_y_ref> y_vec(y_ref);
50 size_t N = stan::math::size(y);
51
52 for (size_t n = 0; n < N; n++) {
53 const T_partials_return y_val = y_vec.val(n);
54 logp += y_val * y_val;
56 partials<0>(ops_partials)[n] -= y_val;
57 }
58 }
59 logp *= -0.5;
61 logp += NEG_LOG_SQRT_TWO_PI * N;
62 }
63
64 return ops_partials.build(logp);
65}
66
67template <typename T_y>
68inline return_type_t<T_y> std_normal_lpdf(const T_y& y) {
69 return std_normal_lpdf<false>(y);
70}
71
72} // namespace math
73} // namespace stan
74#endif
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
return_type_t< T_y_cl > std_normal_lpdf(const T_y_cl &y)
The log of the normal density for the specified scalar(s) given a location of 0 and a scale of 1.
size_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:18
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Definition size_zero.hpp:19
const double NEG_LOG_SQRT_TWO_PI
The value of minus the natural logarithm of the square root of , .
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...