Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
stan
math
rev
scal
fun
floor.hpp
Go to the documentation of this file.
1
#ifndef STAN_MATH_REV_SCAL_FUN_FLOOR_HPP
2
#define STAN_MATH_REV_SCAL_FUN_FLOOR_HPP
3
4
#include <
stan/math/rev/core.hpp
>
5
#include <
stan/math/prim/scal/fun/is_nan.hpp
>
6
#include <
stan/math/prim/scal/meta/likely.hpp
>
7
#include <cmath>
8
#include <limits>
9
10
namespace
stan
{
11
namespace
math
{
12
13
namespace
{
14
class
floor_vari :
public
op_v_vari {
15
public
:
16
explicit
floor_vari(vari* avi) : op_v_vari(
std
::
floor
(avi->val_), avi) {}
17
void
chain
() {
18
if
(
unlikely
(
is_nan
(avi_->val_)))
19
avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
20
}
21
};
22
}
// namespace
23
24
/**
25
* Return the floor of the specified variable (cmath).
26
*
27
* The derivative of the floor function is defined and
28
* zero everywhere but at integers, so we set these derivatives
29
* to zero for convenience,
30
*
31
* \f$\frac{d}{dx} {\lfloor x \rfloor} = 0\f$.
32
*
33
* The floor function rounds down. For double values, this is the largest
34
* integral value that is not greater than the specified value.
35
* Although this function is not differentiable because it is
36
* discontinuous at integral values, its gradient is returned as
37
* zero everywhere.
38
*
39
\f[
40
\mbox{floor}(x) =
41
\begin{cases}
42
\lfloor x \rfloor & \mbox{if } -\infty\leq x \leq \infty \\[6pt]
43
\textrm{NaN} & \mbox{if } x = \textrm{NaN}
44
\end{cases}
45
\f]
46
47
\f[
48
\frac{\partial\, \mbox{floor}(x)}{\partial x} =
49
\begin{cases}
50
0 & \mbox{if } -\infty\leq x\leq \infty \\[6pt]
51
\textrm{NaN} & \mbox{if } x = \textrm{NaN}
52
\end{cases}
53
\f]
54
*
55
* @param a Input variable.
56
* @return Floor of the variable.
57
*/
58
inline
var
floor
(
const
var
&
a
) {
return
var
(
new
floor_vari(a.
vi_
)); }
59
60
}
// namespace math
61
}
// namespace stan
62
#endif
PandAna.Demos.tute_pid_validation.var
list var
Definition:
tute_pid_validation.py:17
core.hpp
is_nan.hpp
stan
Definition:
StanTypedefs.h:9
std
Definition:
SpectrumLoaderBase.h:26
stan::math::var
Definition:
var.hpp:33
a
const double a
Definition:
gUpMuFluxGen.cxx:164
productionTest.chain
chain
Check that an output directory exists.
Definition:
productionTest.py:60
stan::math::var::vi_
vari * vi_
Definition:
var.hpp:45
math
likely.hpp
unlikely
#define unlikely(expr)
Definition:
lz4.cxx:121
stan::math::floor
fvar< T > floor(const fvar< T > &x)
Definition:
floor.hpp:11
stan::math::is_nan
int is_nan(const fvar< T > &x)
Definition:
is_nan.hpp:19
Generated on Fri Mar 5 2021 14:13:38 for NOvA by
1.8.11