Automatic Differentiation
 
Loading...
Searching...
No Matches
deep_copy_vars.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_DEEP_COPY_VARS_HPP
2#define STAN_MATH_REV_CORE_DEEP_COPY_VARS_HPP
3
7
8#include <utility>
9#include <vector>
10
11namespace stan {
12namespace math {
13
22template <typename Arith, typename = require_arithmetic_t<scalar_type_t<Arith>>>
23inline Arith deep_copy_vars(Arith&& arg) {
24 return std::forward<Arith>(arg);
25}
26
33inline auto deep_copy_vars(const var& arg) {
34 return var(new vari(arg.val(), false));
35}
36
44template <typename VarVec, require_std_vector_vt<is_var, VarVec>* = nullptr>
45inline auto deep_copy_vars(VarVec&& arg) {
46 std::vector<var> copy_vec(arg.size());
47 for (size_t i = 0; i < arg.size(); ++i) {
48 copy_vec[i] = new vari(arg[i].val(), false);
49 }
50 return copy_vec;
51}
52
60template <typename VecContainer,
63inline auto deep_copy_vars(VecContainer&& arg) {
64 std::vector<value_type_t<VecContainer>> copy_vec(arg.size());
65 for (size_t i = 0; i < arg.size(); ++i) {
66 copy_vec[i] = deep_copy_vars(arg[i]);
67 }
68 return copy_vec;
69}
70
78template <typename EigT, require_eigen_vt<is_var, EigT>* = nullptr>
79inline auto deep_copy_vars(EigT&& arg) {
80 return arg.unaryExpr([](auto&& x) { return var(new vari(x.val(), false)); })
81 .eval();
82}
83
84} // namespace math
85} // namespace stan
86
87#endif
require_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check... > > require_std_vector_vt
Require type satisfies is_std_vector.
require_t< container_type_check_base< is_std_vector, scalar_type_t, TypeCheck, Check... > > require_std_vector_st
Require type satisfies is_std_vector.
fvar< T > arg(const std::complex< fvar< T > > &z)
Return the phase angle of the complex argument.
Definition arg.hpp:19
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
Definition eval.hpp:20
vari_value< double > vari
Definition vari.hpp:197
Arith deep_copy_vars(Arith &&arg)
Forward arguments that do not contain vars.
var_value< double > var
Definition var.hpp:1187
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...