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 const auto& y_val = as_value_column_vector_or_scalar(y_ref);
47 T_partials_return logp = -dot_self(y_val) / 2.0;
48 auto ops_partials = make_partials_propagator(y_ref);
49
51 partials<0>(ops_partials) = -y_val;
52 }
53
56 }
57
58 return ops_partials.build(logp);
59}
60
61template <typename T_y>
62inline return_type_t<T_y> std_normal_lpdf(const T_y& y) {
63 return std_normal_lpdf<false>(y);
64}
65
66} // namespace math
67} // namespace stan
68#endif
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.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
int64_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:19
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 dot_self(const T &a)
Returns squared norm of a vector or matrix.
Definition dot_self.hpp:21
auto as_value_column_vector_or_scalar(T &&a)
Extract values from input argument and transform to a column vector.
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 ...
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...