Automatic Differentiation
 
Loading...
Searching...
No Matches
subtract.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_SUBTRACT_HPP
2#define STAN_MATH_OPENCL_REV_SUBTRACT_HPP
3#ifdef STAN_OPENCL
4
14
15namespace stan {
16namespace math {
17
27template <typename T_a, typename T_b,
28 require_all_prim_or_rev_kernel_expression_t<T_a, T_b>* = nullptr,
29 require_any_var_t<T_a, T_b>* = nullptr,
30 require_any_not_stan_scalar_t<T_a, T_b>* = nullptr>
31inline auto subtract(T_a&& a, T_b&& b) {
32 arena_t<T_a> a_arena = a;
33 arena_t<T_b> b_arena = b;
34
35 return make_callback_var(
36 value_of(a_arena) - value_of(b_arena),
37 [a_arena, b_arena](vari_value<matrix_cl<double>>& res) mutable {
38 adjoint_results(a_arena, b_arena) += expressions(res.adj(), -res.adj());
39 });
40}
41
51template <
52 typename T_a, typename T_b,
55inline auto operator-(const T_a& a, const T_b& b) {
56 return subtract(a, b);
57}
58
59} // namespace math
60} // namespace stan
61
62#endif
63#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
require_all_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_nonscalar_prim_or_rev_kernel_expression_t
Require all of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
subtraction_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > subtract(T_a &&a, T_b &&b)
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
require_any_t< is_var< std::decay_t< Types > >... > require_any_var_t
Require any of the types satisfy is_var.
Definition is_var.hpp:39
fvar< T > operator-(const fvar< T > &x1, const fvar< T > &x2)
Return the difference of the specified arguments.
adjoint_results_cl< T_results... > adjoint_results(T_results &&... results)
Deduces types for constructing adjoint_results_cl object.
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...