Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dump.hpp
Go to the documentation of this file.
1 #ifndef STAN__IO__DUMP_HPP
2 #define STAN__IO__DUMP_HPP
3 
4 #include <cctype>
5 #include <iostream>
6 #include <limits>
7 #include <map>
8 #include <sstream>
9 #include <stdexcept>
10 #include <string>
11 #include <vector>
12 
13 #include <boost/lexical_cast.hpp>
14 #include <boost/throw_exception.hpp>
15 
16 #include <stan/io/var_context.hpp>
17 #include <stan/math/matrix.hpp>
20 
21 namespace stan {
22 
23  namespace io {
24 
25  namespace {
26  size_t product(std::vector<size_t> dims) {
27  size_t y = 1U;
28  for (size_t i = 0; i < dims.size(); ++i)
29  y *= dims[i];
30  return y;
31  }
32  }
33 
42  class dump_writer {
43  private:
44  std::ostream& out_;
45 
46  // checks doesn't contain quote char
47  void write_name_equals(const std::string& name) {
48  for (size_t i = 0; i < name.size(); ++i)
49  if (name.at(i) == '"')
50  BOOST_THROW_EXCEPTION(
51  std::invalid_argument ("name can not contain quote char"));
52  out_ << '"' << name << '"' << " <- " << '\n';
53  }
54 
55 
56  // adds period at end of output if necessary for double
57  void write_val(const double& x) {
58  std::stringstream ss;
59  ss << x;
60  std::string s;
61  ss >> s;
62  for (std::string::iterator it = s.begin();
63  it < s.end();
64  ++it) {
65  if (*it == '.' || *it == 'e' || *it == 'E') {
66  out_ << s;
67  return;
68  }
69  }
70  out_ << s << ".";
71  }
72 
73  void write_val(const unsigned long long int& n) {
74  out_ << n;
75  }
76 
77  void write_val(const unsigned long int& n) {
78  out_ << n;
79  }
80 
81  void write_val(const unsigned int& n) {
82  out_ << n;
83  }
84 
85  void write_val(const unsigned short& n) {
86  out_ << n;
87  }
88 
89  void write_val(const long long& n) {
90  out_ << n;
91  }
92 
93  void write_val(const long& n) {
94  out_ << n;
95  }
96 
97  void write_val(const int& n) {
98  out_ << n;
99  }
100 
101  void write_val(const short& n) {
102  out_ << n;
103  }
104 
105  void write_val(const char& n) {
106  out_ << n;
107  }
108 
109 
110  template <typename T>
111  void write_list(T xs) {
112  typedef typename stan::math::index_type<T>::type idx_t;
113  out_ << "c(";
114  for (idx_t i = 0; i < xs.size(); ++i) {
115  if (i > 0) out_ << ", ";
116  write_val(xs[i]);
117  }
118  out_ << ")";
119  }
120 
121  template <typename T>
122  void write_structure(std::vector<T> xs,
123  std::vector<size_t> dims) {
124  out_ << "structure(";
125  write_list(xs);
126  out_ << ',' << '\n';
127  out_ << ".Dim = ";
128  write_list(dims);
129  out_ << ")";
130  }
131 
132 
133  void dims(double /*x*/, std::vector<size_t> /*ds*/) {
134  // no op
135  }
136 
137  void dims(int /*x*/, std::vector<size_t> /*ds*/) {
138  // no op
139  }
140 
141  template <typename T>
142  void dims(Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> m,
143  std::vector<size_t> ds) {
144  ds.push_back(m.rows());
145  ds.push_back(m.cols());
146  }
147 
148  template <typename T>
149  void dims(Eigen::Matrix<T,Eigen::Dynamic,1> v,
150  std::vector<size_t> ds) {
151  ds.push_back(v.size());
152  }
153 
154  template <typename T>
155  void dims(Eigen::Matrix<T,1,Eigen::Dynamic> rv,
156  std::vector<size_t> ds) {
157  ds.push_back(rv.size());
158  }
159 
160  template <typename T>
161  void dims(std::vector<T> x, std::vector<size_t> ds) {
162  ds.push_back(x.size());
163  if (x.size() > 0)
164  dims(x[0],ds);
165  }
166 
167  template <typename T>
168  std::vector<size_t> dims(T x) {
169  std::vector<size_t> ds;
170  dims(x,ds);
171  return ds;
172  }
173 
174  bool increment(const std::vector<size_t>& dims,
175  std::vector<size_t>& idx) {
176  for (size_t i = 0; i < dims.size(); ++i) {
177  ++idx[i];
178  if (idx[i] < dims[i]) return true;
179  idx[i] = 0;
180  }
181  return false;
182  }
183 
184  template <typename T>
185  void write_stan_val(const std::vector<T>& x,
186  const std::vector<size_t>& idx,
187  const size_t pos) {
188  size_t next_pos = pos + 1;
189  write_stan_val(x[idx[pos]],idx,next_pos);
190  }
191  void write_stan_val(const std::vector<double>& x,
192  const std::vector<size_t>& idx,
193  const size_t pos) {
194  write_val(x[idx[pos]]);
195  }
196  void write_stan_val(const std::vector<int>& x,
197  const std::vector<size_t>& idx,
198  const size_t pos) {
199  write_val(x[idx[pos]]);
200  }
201  void write_stan_val(const Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& x,
202  const std::vector<size_t>& idx,
203  const size_t pos) {
204  size_t next_pos = pos + 1;
205  write_val(x(idx[pos],idx[next_pos]));
206  }
207  void write_stan_val(const Eigen::Matrix<double,1,Eigen::Dynamic>& x,
208  const std::vector<size_t>& idx,
209  const size_t pos) {
210  write_val(x[idx[pos]]);
211  }
212  void write_stan_val(const Eigen::Matrix<double,Eigen::Dynamic,1>& x,
213  const std::vector<size_t>& idx,
214  const size_t pos) {
215  write_val(x[idx[pos]]);
216  }
217 
218 
219  template <typename T>
220  void write_stan(const std::vector<T>& x) {
221  std::vector<size_t> dims = dims(x);
222  out_ << "structure(c(";
223  std::vector<size_t> idx(dims.size(),0U);
224  for (size_t count = 0; true; ++count) {
225  if (count > 0) out_ << ", ";
226  write_stan_val(x,idx);
227  if (!increment(dims,idx)) break;
228  }
229  out_ << "), .Dim = ";
230  write_list(dims);
231  out_ << ")";
232  }
233  void write_stan(const std::vector<double>& x) {
234  write_list(x);
235  }
236  void write_stan(const std::vector<int>& x) {
237  write_list(x);
238  }
239  void write_stan(double x) {
240  write_val(x);
241  }
242  void write_stan(int x) {
243  write_val(x);
244  }
245  void write_stan(const Eigen::Matrix<double,1,Eigen::Dynamic>& x) {
246  write_list(x);
247  }
248  void write_stan(const Eigen::Matrix<double,Eigen::Dynamic,1>& x) {
249  write_list(x);
250  }
251  void write_stan(const Eigen::Matrix<double,
252  Eigen::Dynamic,Eigen::Dynamic>& x) {
253  typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::Index Index;
254  out_ << "structure(c(";
255  std::vector<double> vals;
256  for (Index m = 0; m < x.cols(); ++m) {
257  for (Index n = 0; n < x.rows(); ++n) {
258  if (m > 0 || n > 0) out_ << ", ";
259  write_val(x(m,n));
260  }
261  }
262  out_ << "), .Dim = c(";
263  out_ << x.rows() << ", " << x.cols();
264  out_ << "))";
265  }
266 
267  public:
268 
272  dump_writer() : out_(std::cout) { }
273 
280  dump_writer(std::ostream& out) : out_(out) { }
281 
286 
305  template <typename T>
306  void write(const std::string& name,
307  const T& x) {
308  write_name_equals(name);
309  write_stan(x);
310  }
311 
321  template <typename T>
322  void dump_structure(std::string /*name*/,
323  std::vector<size_t> dims,
324  std::vector<T> xs) {
325  if (xs.size() != product(dims))
326  BOOST_THROW_EXCEPTION(
327  std::invalid_argument ("xs.size() != product(dims)"));
328  write_structure(xs,dims);
329  }
330 
339  template <typename T>
340  void dump_list(std::string name,
341  std::vector<T> xs) {
342  write_name_equals(name);
343  write_list(xs);
344  }
345 
354  template <typename T>
355  void dump_var(std::string name,
356  T x) {
357  write_name_equals(name);
358  write_val(x);
359  }
360 
361  };
362 
434  class dump_reader {
435  private:
436  std::string buf_;
437  std::string name_;
438  std::vector<int> stack_i_;
439  std::vector<double> stack_r_;
440  std::vector<size_t> dims_;
441  std::istream& in_;
442 
443  bool scan_single_char(char c_expected) {
444  int c = in_.peek();
445  if (in_.fail()) return false;
446  if (c != c_expected)
447  return false;
448  char c_skip;
449  in_.get(c_skip);
450  return true;
451  }
452 
453  bool scan_optional_long() {
454  if (scan_single_char('l'))
455  return true;
456  else if (scan_single_char('L'))
457  return true;
458  else
459  return false;
460  }
461 
462  bool scan_char(char c_expected) {
463  char c;
464  in_ >> c;
465  if (in_.fail()) return false;
466  if (c != c_expected) {
467  in_.putback(c);
468  return false;
469  }
470  return true;
471  }
472 
473  bool scan_name_unquoted() {
474  char c;
475  in_ >> c; //
476  if (in_.fail()) return false;
477  if (!std::isalpha(c)) return false;
478  name_.push_back(c);
479  while (in_.get(c)) { // get turns off auto space skip
480  if (std::isalpha(c) || std::isdigit(c) || c == '_' || c == '.') {
481  name_.push_back(c);
482  } else {
483  in_.putback(c);
484  return true;
485  }
486  }
487  return true; // but hit eos
488  }
489 
490  bool scan_name() {
491  if (scan_char('"')) {
492  if (!scan_name_unquoted()) return false;
493  if (!scan_char('"')) return false;
494  } else if (scan_char('\'')) {
495  if (!scan_name_unquoted()) return false;
496  if (!scan_char('\'')) return false;
497  } else {
498  if (!scan_name_unquoted()) return false;
499  }
500  return true;
501  }
502 
503 
504  bool scan_chars(const char *s, bool case_sensitive = true) {
505  for (size_t i = 0; s[i]; ++i) {
506  char c;
507  if (!(in_ >> c)) {
508  for (size_t j = 1; j < i; ++j)
509  in_.putback(s[i-j]);
510  return false;
511  }
512  // all ASCII, so toupper is OK
513  if ((case_sensitive && c != s[i])
514  || (!case_sensitive && ::toupper(c) != ::toupper(s[i]))) {
515  in_.putback(c);
516  for (size_t j = 1; j < i; ++j)
517  in_.putback(s[i-j]);
518  return false;
519  }
520  }
521  return true;
522  }
523 
524  bool scan_chars(std::string s, bool case_sensitive = true) {
525  for (size_t i = 0; i < s.size(); ++i) {
526  char c;
527  if (!(in_ >> c)) {
528  for (size_t j = 1; j < i; ++j)
529  in_.putback(s[i-j]);
530  return false;
531  }
532  // all ASCII, so toupper is OK
533  if ((case_sensitive && c != s[i])
534  || (!case_sensitive && ::toupper(c) != ::toupper(s[i]))) {
535  in_.putback(c);
536  for (size_t j = 1; j < i; ++j)
537  in_.putback(s[i-j]);
538  return false;
539  }
540  }
541  return true;
542  }
543 
544  size_t scan_dim() {
545  char c;
546  buf_.clear();
547  while (in_.get(c)) {
548  if (std::isspace(c)) continue;
549  if (std::isdigit(c)) {
550  buf_.push_back(c);
551  } else {
552  in_.putback(c);
553  break;
554  }
555  }
556  scan_optional_long();
557  size_t d = 0;
558  try {
559  d = boost::lexical_cast<size_t>(buf_);
560  }
561  catch ( const boost::bad_lexical_cast &exc ) {
562  std::string msg = "value " + buf_ + " beyond array dimension range";
563  BOOST_THROW_EXCEPTION (std::invalid_argument (msg));
564  }
565  return d;
566  }
567 
568  int scan_int() {
569  char c;
570  buf_.clear();
571  while (in_.get(c)) {
572  if (std::isspace(c)) continue;
573  if (std::isdigit(c)) {
574  buf_.push_back(c);
575  } else {
576  in_.putback(c);
577  break;
578  }
579  }
580  return(get_int());
581  }
582 
583  int get_int() {
584  int n = 0;
585  try {
586  n = boost::lexical_cast<int>(buf_);
587  }
588  catch ( const boost::bad_lexical_cast &exc ) {
589  std::string msg = "value " + buf_ + " beyond int range";
590  BOOST_THROW_EXCEPTION (std::invalid_argument (msg));
591  }
592  return n;
593  }
594 
595  double scan_double() {
596  double x = 0;
597  try {
598  x = boost::lexical_cast<double>(buf_);
599  }
600  catch ( const boost::bad_lexical_cast &exc ) {
601  std::string msg = "value " + buf_ + " beyond numeric range";
602  BOOST_THROW_EXCEPTION (std::invalid_argument (msg));
603  }
604  return x;
605  }
606 
607 
608 
609  // scan number stores number or throws bad lexical cast exception
610  void scan_number(bool negate_val) {
611  // must take longest first!
612  if (scan_chars("Inf")) {
613  scan_chars("inity"); // read past if there
614  stack_r_.push_back(negate_val
615  ? -std::numeric_limits<double>::infinity()
616  : std::numeric_limits<double>::infinity());
617  return;
618  }
619  if (scan_chars("NaN",false)) {
620  stack_r_.push_back(std::numeric_limits<double>::quiet_NaN());
621  return;
622  }
623 
624  char c;
625  bool is_double = false;
626  buf_.clear();
627  while (in_.get(c)) {
628  if (std::isdigit(c)) { // before pre-scan || c == '-' || c == '+') {
629  buf_.push_back(c);
630  } else if (c == '.'
631  || c == 'e'
632  || c == 'E'
633  || c == '-'
634  || c == '+') {
635  is_double = true;
636  buf_.push_back(c);
637  } else {
638  in_.putback(c);
639  break;
640  }
641  }
642  if (!is_double && stack_r_.size() == 0) {
643  int n = get_int();
644  stack_i_.push_back(negate_val ? -n : n);
645  scan_optional_long();
646  } else {
647  for (size_t j = 0; j < stack_i_.size(); ++j)
648  stack_r_.push_back(static_cast<double>(stack_i_[j]));
649  stack_i_.clear();
650  double x = scan_double();
651  stack_r_.push_back(negate_val ? -x : x);
652  }
653  }
654 
655  void scan_number() {
656  char c;
657  while (in_.get(c)) {
658  if (std::isspace(c)) continue;
659  in_.putback(c);
660  break;
661  }
662  bool negate_val = scan_char('-');
663  if (!negate_val) scan_char('+'); // flush leading +
664  return scan_number(negate_val);
665  }
666 
667 
668  bool scan_seq_value() {
669  if (!scan_char('(')) return false;
670  if (scan_char(')')) {
671  dims_.push_back(0U);
672  return true;
673  }
674  scan_number(); // first entry
675  while (scan_char(',')) {
676  scan_number();
677  }
678  dims_.push_back(stack_r_.size() + stack_i_.size());
679  return scan_char(')');
680  }
681 
682  bool scan_struct_value() {
683  if (!scan_char('(')) return false;
684  if (scan_char('c')) {
685  scan_seq_value();
686  } else {
687  int start = scan_int();
688  if (!scan_char(':'))
689  return false;
690  int end = scan_int();
691  if (start <= end) {
692  for (int i = start; i <= end; ++i)
693  stack_i_.push_back(i);
694  } else {
695  for (int i = start; i >= end; --i)
696  stack_i_.push_back(i);
697  }
698  }
699  dims_.clear();
700  if (!scan_char(',')) return false;
701  if (!scan_char('.')) return false;
702  if (!scan_chars("Dim")) return false;
703  if (!scan_char('=')) return false;
704  if (scan_char('c')) {
705  if (!scan_char('(')) return false;
706  size_t dim = scan_dim();
707  dims_.push_back(dim);
708  while (scan_char(',')) {
709  dim = scan_dim();
710  dims_.push_back(dim);
711  }
712  if (!scan_char(')')) return false;
713  }
714  else {
715  size_t start = scan_dim();
716  if (!scan_char(':'))
717  return false;
718  size_t end = scan_dim();
719  if (start < end) {
720  for (size_t i = start; i <= end; ++i)
721  dims_.push_back(i);
722  } else {
723  for (size_t i = start; i >= end; --i)
724  dims_.push_back(i);
725  }
726  }
727  if (!scan_char(')')) return false;
728  return true;
729  }
730 
731  bool scan_value() {
732  if (scan_char('c'))
733  return scan_seq_value();
734  if (scan_chars("structure"))
735  return scan_struct_value();
736  scan_number();
737  if (!scan_char(':'))
738  return true;
739  if (stack_i_.size() != 1)
740  return false;
741  scan_number();
742  if (stack_i_.size() != 2)
743  return false;
744  int start = stack_i_[0];
745  int end = stack_i_[1];
746  stack_i_.clear();
747  if (start <= end) {
748  for (int i = start; i <= end; ++i)
749  stack_i_.push_back(i);
750  } else {
751  for (int i = start; i >= end; --i)
752  stack_i_.push_back(i);
753  }
754  dims_.push_back(stack_i_.size());
755  return true;
756  }
757 
761  void print() {
762  std::cout << "var name=|" << name_ << "|" << std::endl;
763  std:: cout << "dims=(";
764  for (size_t i = 0; i < dims_.size(); ++i) {
765  if (i > 0)
766  std::cout << ",";
767  std::cout << dims_[i];
768  }
769  std::cout << ")" << std::endl;
770  std::cout << "float stack:" << std::endl;
771  for (size_t i = 0; i < stack_r_.size(); ++i)
772  std::cout << " [" << i << "] " << stack_r_[i] << std::endl;
773  std::cout << "int stack" << std::endl;
774  for (size_t i = 0; i < stack_i_.size(); ++i)
775  std::cout << " [" << i << "] " << stack_i_[i] << std::endl;
776  }
777 
778 
779  public:
783  dump_reader() : in_(std::cin) { }
784 
790  dump_reader(std::istream& in) : in_(in) { }
791 
796 
797 
803  std::string name() {
804  return name_;
805  }
806 
813  std::vector<size_t> dims() {
814  return dims_;
815  }
816 
824  bool is_int() {
825  // return stack_i_.size() > 0;
826  return stack_r_.size() == 0;
827  }
828 
835  std::vector<int> int_values() {
836  return stack_i_;
837  }
838 
846  std::vector<double> double_values() {
847  return stack_r_;
848  }
849 
858  bool next() {
859  stack_r_.clear();
860  stack_i_.clear();
861  dims_.clear();
862  name_.erase();
863  if (!scan_name()) // set name
864  return false;
865  if (!scan_char('<')) // set <-
866  return false;
867  if (!scan_char('-'))
868  return false;
869  try {
870  bool okSyntax = scan_value(); // set stack_r_, stack_i_, dims_
871  if (!okSyntax) {
872  std::string msg = "syntax error";
873  BOOST_THROW_EXCEPTION (std::invalid_argument (msg));
874  }
875  }
876  catch (const std::invalid_argument &e) {
877  std::string msg = "data " + name_ + " " + e.what();
878  BOOST_THROW_EXCEPTION (std::invalid_argument (msg));
879  }
880  return true;
881  }
882 
883  };
884 
885 
886 
902  class dump : public stan::io::var_context {
903  private:
904  std::map<std::string,
905  std::pair<std::vector<double>,
906  std::vector<size_t> > > vars_r_;
907  std::map<std::string,
908  std::pair<std::vector<int>,
909  std::vector<size_t> > > vars_i_;
910  std::vector<double> const empty_vec_r_;
911  std::vector<int> const empty_vec_i_;
912  std::vector<size_t> const empty_vec_ui_;
922  bool contains_r_only(const std::string& name) const {
923  return vars_r_.find(name) != vars_r_.end();
924  }
925  public:
926 
934  dump(std::istream& in) {
935  dump_reader reader(in);
936  while (reader.next()) {
937  if (reader.is_int()) {
938  vars_i_[reader.name()]
939  = std::pair<std::vector<int>,
940  std::vector<size_t> >(reader.int_values(),
941  reader.dims());
942 
943  } else {
944  vars_r_[reader.name()]
945  = std::pair<std::vector<double>,
946  std::vector<size_t> >(reader.double_values(),
947  reader.dims());
948  }
949  }
950  }
951 
960  bool contains_r(const std::string& name) const {
961  return contains_r_only(name) || contains_i(name);
962  }
963 
972  bool contains_i(const std::string& name) const {
973  return vars_i_.find(name) != vars_i_.end();
974  }
975 
983  std::vector<double> vals_r(const std::string& name) const {
984  if (contains_r_only(name)) {
985  return (vars_r_.find(name)->second).first;
986  } else if (contains_i(name)) {
987  std::vector<int> vec_int = (vars_i_.find(name)->second).first;
988  std::vector<double> vec_r(vec_int.size());
989  for (size_t ii = 0; ii < vec_int.size(); ii++) {
990  vec_r[ii] = vec_int[ii];
991  }
992  return vec_r;
993  }
994  return empty_vec_r_;
995  }
996 
1004  std::vector<size_t> dims_r(const std::string& name) const {
1005  if (contains_r_only(name)) {
1006  return (vars_r_.find(name)->second).second;
1007  } else if (contains_i(name)) {
1008  return (vars_i_.find(name)->second).second;
1009  }
1010  return empty_vec_ui_;
1011  }
1012 
1020  std::vector<int> vals_i(const std::string& name) const {
1021  if (contains_i(name)) {
1022  return (vars_i_.find(name)->second).first;
1023  }
1024  return empty_vec_i_;
1025  }
1026 
1034  std::vector<size_t> dims_i(const std::string& name) const {
1035  if (contains_i(name)) {
1036  return (vars_i_.find(name)->second).second;
1037  }
1038  return empty_vec_ui_;
1039  }
1040 
1047  virtual void names_r(std::vector<std::string>& names) const {
1048  names.resize(0);
1049  for (std::map<std::string,
1050  std::pair<std::vector<double>,
1051  std::vector<size_t> > >
1052  ::const_iterator it = vars_r_.begin();
1053  it != vars_r_.end(); ++it)
1054  names.push_back((*it).first);
1055  }
1056 
1063  virtual void names_i(std::vector<std::string>& names) const {
1064  names.resize(0);
1065  for (std::map<std::string,
1066  std::pair<std::vector<int>,
1067  std::vector<size_t> > >
1068  ::const_iterator it = vars_i_.begin();
1069  it != vars_i_.end(); ++it)
1070  names.push_back((*it).first);
1071  }
1072 
1080  bool remove(const std::string& name) {
1081  return (vars_i_.erase(name) > 0)
1082  || (vars_r_.erase(name) > 0);
1083  }
1084 
1085  };
1086 
1087  }
1088 
1089 }
1090 #endif
dump(std::istream &in)
Construct a dump object from the specified input stream.
Definition: dump.hpp:934
dump_writer()
Construct a dump writer writing to standard output.
Definition: dump.hpp:272
void write(const std::string &name, const T &x)
Write a variable with the specified name and value.
Definition: dump.hpp:306
~dump_reader()
Destroy this reader.
Definition: dump.hpp:795
void dump_structure(std::string, std::vector< size_t > dims, std::vector< T > xs)
Write a structure variable with the specified name, dimensions, and integer or double values...
Definition: dump.hpp:322
~dump_writer()
Destroy this writer.
Definition: dump.hpp:285
bool is_int()
Checks if the last item read is integer.
Definition: dump.hpp:824
Writes data into the S-plus dump format.
Definition: dump.hpp:42
virtual void names_r(std::vector< std::string > &names) const
Return a list of the names of the floating point variables in the dump.
Definition: dump.hpp:1047
bool contains_r(const std::string &name) const
Return true if this dump contains the specified variable name is defined.
Definition: dump.hpp:960
std::vector< double > double_values()
Returns the floating point values from the last item if the last item read contained floating point v...
Definition: dump.hpp:846
virtual void names_i(std::vector< std::string > &names) const
Return a list of the names of the integer variables in the dump.
Definition: dump.hpp:1063
void dump_list(std::string name, std::vector< T > xs)
Write a list variable with the specified name and integer or double values.
Definition: dump.hpp:340
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
A stream-based reader for integer, scalar, vector, matrix and array data types, with Jacobian calcula...
Definition: reader.hpp:34
void dump_var(std::string name, T x)
Write a list variable with the specified name and integer or double values.
Definition: dump.hpp:355
void dims(const T &x, std::vector< int > &result)
Definition: dims.hpp:13
bool contains_i(const std::string &name) const
Return true if this dump contains an integer valued array with the specified name.
Definition: dump.hpp:972
A var_reader reads array variables of integer and floating point type by name and dimension...
Definition: var_context.hpp:29
std::vector< size_t > dims_r(const std::string &name) const
Return the dimensions for the double variable with the specified name.
Definition: dump.hpp:1004
std::vector< int > int_values()
Returns the integer values from the last item if the last item read was an integer and the empty vect...
Definition: dump.hpp:835
std::vector< double > vals_r(const std::string &name) const
Return the double values for the variable with the specified name or null.
Definition: dump.hpp:983
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:86
dump_writer(std::ostream &out)
Construct a dump writer writing to the specified output stream.
Definition: dump.hpp:280
std::string name()
Return the name of the most recently read variable.
Definition: dump.hpp:803
std::vector< size_t > dims()
Return the dimensions of the most recently read variable.
Definition: dump.hpp:813
std::vector< int > vals_i(const std::string &name) const
Return the integer values for the variable with the specified name.
Definition: dump.hpp:1020
dump_reader()
Construct a reader for standard input.
Definition: dump.hpp:783
Reads data from S-plus dump format.
Definition: dump.hpp:434
Represents named arrays with dimensions.
Definition: dump.hpp:902
bool next()
Read the next value from the input stream, returning true if successful and false if no further input...
Definition: dump.hpp:858
dump_reader(std::istream &in)
Construct a reader for the specified input stream.
Definition: dump.hpp:790
std::vector< size_t > dims_i(const std::string &name) const
Return the dimensions for the integer variable with the specified name.
Definition: dump.hpp:1034

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