-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_var.hpp
48 lines (43 loc) · 1.24 KB
/
to_var.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef STAN_MATH_TORSTEN_TO_VAR
#define STAN_MATH_TORSTEN_TO_VAR
#include <stan/math/prim/fun/value_of.hpp>
#include <stan/math/rev/fun/value_of.hpp>
#include <stan/math/rev/fun/to_var.hpp>
#include <stan/math/rev/core/var.hpp>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
namespace torsten {
template<typename T>
std::vector<std::vector<stan::math::var> > to_var(const std::vector<std::vector<T> >& d)
{
std::vector<std::vector<stan::math::var> > res(d.size());
for (size_t i = 0; i < d.size(); ++i) {
res[i].resize(d[i].size());
for (size_t j = 0; j < d[i].size(); ++j) {
res[i][j] = stan::math::value_of(d[i][j]);
}
}
return res;
}
template<typename T>
std::vector<stan::math::var> to_var(const std::vector<T>& d)
{
std::vector<stan::math::var> res(d.size());
for (size_t i = 0; i < d.size(); ++i) {
res[i] = stan::math::value_of(d[i]);
}
return res;
}
template<typename T>
std::vector<stan::math::matrix_v> to_var(const std::vector<Eigen::Matrix<T, -1, -1> >& d)
{
std::vector<stan::math::matrix_v> res(d.size());
for (size_t i = 0; i < d.size(); ++i) {
res[i] = stan::math::value_of(d[i]);
}
return res;
}
}
#endif