Automatic Differentiation
 
Loading...
Searching...
No Matches
operands_and_partials.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_OPERANDS_AND_PARTIALS_HPP
2#define STAN_MATH_PRIM_FUNCTOR_OPERANDS_AND_PARTIALS_HPP
3
8#include <vector>
9#include <type_traits>
10#include <tuple>
11
12namespace stan {
13namespace math {
14
15template <typename Op1 = double, typename Op2 = double, typename Op3 = double,
16 typename Op4 = double, typename Op5 = double, typename Op6 = double,
17 typename Op7 = double, typename Op8 = double,
18 typename T_return_type
19 = return_type_t<Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8>>
20class operands_and_partials; // Forward declaration
21
22namespace internal {
23
44template <typename ViewElt, typename Op, typename Enable = void>
46
56template <typename ViewElt, typename Op>
57struct ops_partials_edge<ViewElt, Op, require_st_arithmetic<Op>> {
58 using inner_op = std::conditional_t<is_eigen<value_type_t<Op>>::value,
69 static constexpr double operands_{0};
70 ops_partials_edge() = default;
71
72 template <typename T,
74 std::decay_t<T>,
75 std::decay_t<ops_partials_edge<
76 ViewElt, Op, require_st_arithmetic<Op>>>>* = nullptr>
77 constexpr explicit ops_partials_edge(T&& /* op */) noexcept {}
78
83 static constexpr double operand() noexcept {
84 return static_cast<double>(0.0);
85 }
86
91 static constexpr double partial() noexcept {
92 return static_cast<double>(0.0);
93 }
98 static constexpr double dx() noexcept { return static_cast<double>(0); }
103 static constexpr int size() noexcept { return 0; } // reverse mode
104};
105
106template <typename ViewElt, typename Op>
107constexpr double
108 ops_partials_edge<ViewElt, Op, require_st_arithmetic<Op>>::operands_;
109
110} // namespace internal
111
150template <typename Op1, typename Op2, typename Op3, typename Op4, typename Op5,
151 typename Op6, typename Op7, typename Op8, typename T_return_type>
153 public:
154 explicit operands_and_partials(const Op1& /* op1 */) noexcept {}
155 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */) noexcept {}
156 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
157 const Op3& /* op3 */) noexcept {}
158 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
159 const Op3& /* op3 */, const Op4& /* op4 */) noexcept {}
160 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
161 const Op3& /* op3 */, const Op4& /* op4 */,
162 const Op5& /* op5 */) noexcept {}
163 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
164 const Op3& /* op3 */, const Op4& /* op4 */,
165 const Op5& /* op5 */, const Op6& /* op6 */) noexcept {}
166 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
167 const Op3& /* op3 */, const Op4& /* op4 */,
168 const Op5& /* op5 */, const Op6& /* op6 */,
169 const Op7& /* op7 */) noexcept {}
170 operands_and_partials(const Op1& /* op1 */, const Op2& /* op2 */,
171 const Op3& /* op3 */, const Op4& /* op4 */,
172 const Op5& /* op5 */, const Op6& /* op6 */,
173 const Op7& /* op7 */, const Op8& /* op8 */) noexcept {}
174
188 inline double build(double value) const noexcept { return value; }
189
190 // These will always be 0 size base template instantiations (above).
199};
200
201} // namespace math
202} // namespace stan
203#endif
An edge holds both the operands and its associated partial derivatives.
internal::ops_partials_edge< double, std::decay_t< Op2 > > edge2_
internal::ops_partials_edge< double, std::decay_t< Op7 > > edge7_
internal::ops_partials_edge< double, std::decay_t< Op4 > > edge4_
operands_and_partials(const Op1 &, const Op2 &, const Op3 &) noexcept
operands_and_partials(const Op1 &, const Op2 &, const Op3 &, const Op4 &, const Op5 &) noexcept
operands_and_partials(const Op1 &, const Op2 &, const Op3 &, const Op4 &) noexcept
operands_and_partials(const Op1 &, const Op2 &, const Op3 &, const Op4 &, const Op5 &, const Op6 &, const Op7 &, const Op8 &) noexcept
operands_and_partials(const Op1 &, const Op2 &, const Op3 &, const Op4 &, const Op5 &, const Op6 &) noexcept
operands_and_partials(const Op1 &, const Op2 &) noexcept
internal::ops_partials_edge< double, std::decay_t< Op6 > > edge6_
internal::ops_partials_edge< double, std::decay_t< Op1 > > edge1_
internal::ops_partials_edge< double, std::decay_t< Op8 > > edge8_
internal::ops_partials_edge< double, std::decay_t< Op5 > > edge5_
operands_and_partials(const Op1 &, const Op2 &, const Op3 &, const Op4 &, const Op5 &, const Op6 &, const Op7 &) noexcept
internal::ops_partials_edge< double, std::decay_t< Op3 > > edge3_
This template builds partial derivatives with respect to a set of operands.
require_t< std::is_arithmetic< scalar_type_t< std::decay_t< T > > > > require_st_arithmetic
Require scalar type satisfies std::is_arithmetic.
require_not_t< std::is_same< std::decay_t< T >, std::decay_t< S > > > require_not_same_t
Require types T and S does not satisfy std::is_same.
double build(double value) const noexcept
Build the node to be stored on the autodiff graph.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
static constexpr double dx() noexcept
Return the tangent for the edge.
static constexpr int size() noexcept
Return the size of the operand for the edge.
partials_t partials_
The partials_ are always called in if statements that will be removed by the dead code elimination pa...
std::conditional_t< is_eigen< value_type_t< Op > >::value, value_type_t< Op >, Op > inner_op
static constexpr double operand() noexcept
Get the operand for the edge.
static constexpr double partial() noexcept
Get the partial for the edge.