Automatic Differentiation
 
Loading...
Searching...
No Matches
sign.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SIGN_HPP
2#define STAN_MATH_PRIM_FUN_SIGN_HPP
3
6
7namespace stan {
8namespace math {
9
10// returns 1 if NaN is passed in.
11template <typename T, require_stan_scalar_t<T>* = nullptr>
12inline int sign(const T& z) {
13 return (z == 0) ? 0 : z < 0 ? -1 : 1;
14}
15
19struct sign_fun {
27 template <typename T>
28 static inline int fun(const T& x) {
29 return sign(x);
30 }
31};
32
41template <typename T, require_container_t<T>* = nullptr>
42inline auto sign(const T& x) {
43 return apply_scalar_unary<sign_fun, T>::apply(x);
44}
45
46} // namespace math
47} // namespace stan
48
49#endif
auto sign(const T &x)
Returns signs of the arguments.
Definition sign.hpp:18
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
static int fun(const T &x)
Return the sign of the specified argument.
Definition sign.hpp:28
Structure to wrap sign() so it can be vectorized.
Definition sign.hpp:19