Stan Math Library  2.14.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) *o << ',';
21  stan_print(o, x[i]);
22  }
23  *o << ']';
24  }
25 
26  template <typename T>
27  void stan_print(std::ostream* o,
28  const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
29  *o << '[';
30  for (int i = 0; i < x.size(); ++i) {
31  if (i > 0) *o << ',';
32  stan_print(o, x(i));
33  }
34  *o << ']';
35  }
36 
37  template <typename T>
38  void stan_print(std::ostream* o,
39  const Eigen::Matrix<T, 1, Eigen::Dynamic>& x) {
40  *o << '[';
41  for (int i = 0; i < x.size(); ++i) {
42  if (i > 0) *o << ',';
43  stan_print(o, x(i));
44  }
45  *o << ']';
46  }
47 
48  template <typename T>
49  void stan_print(std::ostream* o,
50  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& x) {
51  *o << '[';
52  for (int i = 0; i < x.rows(); ++i) {
53  if (i > 0) *o << ',';
54  *o << '[';
55  for (int j = 0; j < x.row(i).size(); ++j) {
56  if (j > 0) *o << ',';
57  stan_print(o, x.row(i)(j));
58  }
59  *o << ']';
60  }
61  *o << ']';
62  }
63 
64  }
65 }
66 #endif
void stan_print(std::ostream *o, const T &x)
Definition: stan_print.hpp:12

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