Stan Math Library  2.20.0
reverse mode automatic differentiation
stan_print.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_STAN_PRINT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_STAN_PRINT_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 namespace math {
9 // prints used in generator for print() statements in modeling language
10 
11 template <typename T>
12 void stan_print(std::ostream* o, const T& x) {
13  *o << x;
14 }
15 
16 template <typename T>
17 void stan_print(std::ostream* o, const std::vector<T>& x) {
18  *o << '[';
19  for (size_t i = 0; i < x.size(); ++i) {
20  if (i > 0)
21  *o << ',';
22  stan_print(o, x[i]);
23  }
24  *o << ']';
25 }
26 
27 template <typename T>
28 void stan_print(std::ostream* o, const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
29  *o << '[';
30  for (int i = 0; i < x.size(); ++i) {
31  if (i > 0)
32  *o << ',';
33  stan_print(o, x(i));
34  }
35  *o << ']';
36 }
37 
38 template <typename T>
39 void stan_print(std::ostream* o, const Eigen::Matrix<T, 1, Eigen::Dynamic>& x) {
40  *o << '[';
41  for (int i = 0; i < x.size(); ++i) {
42  if (i > 0)
43  *o << ',';
44  stan_print(o, x(i));
45  }
46  *o << ']';
47 }
48 
49 template <typename T>
50 void stan_print(std::ostream* o,
51  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& x) {
52  *o << '[';
53  for (int i = 0; i < x.rows(); ++i) {
54  if (i > 0)
55  *o << ',';
56  *o << '[';
57  for (int j = 0; j < x.row(i).size(); ++j) {
58  if (j > 0)
59  *o << ',';
60  stan_print(o, x.row(i)(j));
61  }
62  *o << ']';
63  }
64  *o << ']';
65 }
66 
67 } // namespace math
68 } // namespace stan
69 #endif
void stan_print(std::ostream *o, const T &x)
Definition: stan_print.hpp:12

     [ Stan Home Page ] © 2011–2018, Stan Development Team.