Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
stan::io::chained_var_context Class Reference

#include "stan/io/chained_var_context.hpp"

Inheritance diagram for stan::io::chained_var_context:
stan::io::var_context

Public Member Functions

 chained_var_context (const var_context &v1, const var_context &v2)
 
bool contains_i (const std::string &name) const
 
bool contains_r (const std::string &name) const
 
std::vector< double > vals_r (const std::string &name) const
 
std::vector< intvals_i (const std::string &name) const
 
std::vector< size_t > dims_r (const std::string &name) const
 
std::vector< size_t > dims_i (const std::string &name) const
 
void names_r (std::vector< std::string > &names) const
 
void names_i (std::vector< std::string > &names) const
 
void add_vec (std::stringstream &msg, const std::vector< size_t > &dims) const
 
void validate_dims (const std::string &stage, const std::string &name, const std::string &base_type, const std::vector< size_t > &dims_declared) const
 

Static Public Member Functions

static std::vector< size_t > to_vec ()
 
static std::vector< size_t > to_vec (size_t n1)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7)
 
static std::vector< size_t > to_vec (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t n6, size_t n7, size_t n8)
 

Private Attributes

const var_contextvc1_
 
const var_contextvc2_
 

Detailed Description

A chained_var_context object represents two objects of var_context as one.

Definition at line 15 of file chained_var_context.hpp.

Constructor & Destructor Documentation

stan::io::chained_var_context::chained_var_context ( const var_context v1,
const var_context v2 
)
inline

Definition at line 21 of file chained_var_context.hpp.

21  :
22  vc1_(v1), vc2_(v2) {
23  }

Member Function Documentation

void stan::io::var_context::add_vec ( std::stringstream &  msg,
const std::vector< size_t > &  dims 
) const
inlineinherited

Definition at line 114 of file var_context.hpp.

References MECModelEnuComparisons::i.

Referenced by stan::io::var_context::validate_dims().

115  {
116  msg << '(';
117  for (size_t i = 0; i < dims.size(); ++i) {
118  if (i > 0) msg << ',';
119  msg << dims[i];
120  }
121  msg << ')';
122  }
bool stan::io::chained_var_context::contains_i ( const std::string &  name) const
inlinevirtual

Return true if the specified variable name has integer values.

Parameters
nameName of variable.
Returns
true if an integer variable of the specified name is defined.

Implements stan::io::var_context.

Definition at line 25 of file chained_var_context.hpp.

References stan::io::var_context::contains_i().

25  {
26  return vc1_.contains_i(name) || vc2_.contains_i(name);
27  }
const XML_Char * name
Definition: expat.h:151
virtual bool contains_i(const std::string &name) const =0
bool stan::io::chained_var_context::contains_r ( const std::string &  name) const
inlinevirtual

Return true if the specified variable name is defined. This method should return true even if the values are all integers.

Parameters
nameName of variable.
Returns
true if the variable exists with real values.

Implements stan::io::var_context.

Definition at line 29 of file chained_var_context.hpp.

References stan::io::var_context::contains_r().

Referenced by TEST().

29  {
30  return vc1_.contains_r(name) || vc2_.contains_r(name);
31  }
const XML_Char * name
Definition: expat.h:151
virtual bool contains_r(const std::string &name) const =0
std::vector<size_t> stan::io::chained_var_context::dims_i ( const std::string &  name) const
inlinevirtual

Return the dimensions of the specified floating point variable. If the variable doesn't exist (or if it is a scalar), the return result should be the empty vector.

Parameters
nameName of variable.
Returns
Sequence of dimensions for the variable.

Implements stan::io::var_context.

Definition at line 45 of file chained_var_context.hpp.

References stan::io::var_context::contains_r(), and stan::io::var_context::dims_i().

45  {
47  }
const XML_Char * name
Definition: expat.h:151
virtual bool contains_r(const std::string &name) const =0
virtual std::vector< size_t > dims_i(const std::string &name) const =0
std::vector<size_t> stan::io::chained_var_context::dims_r ( const std::string &  name) const
inlinevirtual

Return the dimensions for the specified floating point variable. If the variable doesn't exist or if it is a scalar, the return result should be the empty vector.

Parameters
nameName of variable.
Returns
Sequence of dimensions for the variable.

Implements stan::io::var_context.

Definition at line 41 of file chained_var_context.hpp.

References stan::io::var_context::contains_r(), and stan::io::var_context::dims_r().

41  {
43  }
const XML_Char * name
Definition: expat.h:151
virtual bool contains_r(const std::string &name) const =0
virtual std::vector< size_t > dims_r(const std::string &name) const =0
void stan::io::chained_var_context::names_i ( std::vector< std::string > &  names) const
inlinevirtual

Fill a list of the names of the integer variables in the context.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 56 of file chained_var_context.hpp.

References stan::io::var_context::names_i().

56  {
58  std::vector<std::string> names2;
59  vc2_.names_i(names2);
60  names.insert(names.end(), names2.begin(), names2.end());
61  }
virtual void names_i(std::vector< std::string > &names) const =0
void stan::io::chained_var_context::names_r ( std::vector< std::string > &  names) const
inlinevirtual

Fill a list of the names of the floating point variables in the context.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 49 of file chained_var_context.hpp.

References stan::io::var_context::names_r().

49  {
51  std::vector<std::string> names2;
52  vc2_.names_r(names2);
53  names.insert(names.end(), names2.begin(), names2.end());
54  }
virtual void names_r(std::vector< std::string > &names) const =0
static std::vector<size_t> stan::io::var_context::to_vec ( )
inlinestaticinherited

Definition at line 179 of file var_context.hpp.

Referenced by stan::services::util::read_dense_inv_metric(), stan::services::util::read_diag_inv_metric(), and TEST().

179  {
180  return std::vector<size_t>();
181  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1)
inlinestaticinherited

Definition at line 182 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

182  {
183  std::vector<size_t> v(1);
184  v[0] = n1;
185  return v;
186  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2 
)
inlinestaticinherited

Definition at line 187 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

187  {
188  std::vector<size_t> v(2);
189  v[0] = n1;
190  v[1] = n2;
191  return v;
192  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3 
)
inlinestaticinherited

Definition at line 193 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

194  {
195  std::vector<size_t> v(3);
196  v[0] = n1;
197  v[1] = n2;
198  v[2] = n3;
199  return v;
200  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4 
)
inlinestaticinherited

Definition at line 201 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

202  {
203  std::vector<size_t> v(4);
204  v[0] = n1;
205  v[1] = n2;
206  v[2] = n3;
207  v[3] = n4;
208  return v;
209  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4,
size_t  n5 
)
inlinestaticinherited

Definition at line 210 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

212  {
213  std::vector<size_t> v(5);
214  v[0] = n1;
215  v[1] = n2;
216  v[2] = n3;
217  v[3] = n4;
218  v[4] = n5;
219  return v;
220  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4,
size_t  n5,
size_t  n6 
)
inlinestaticinherited

Definition at line 221 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

223  {
224  std::vector<size_t> v(6);
225  v[0] = n1;
226  v[1] = n2;
227  v[2] = n3;
228  v[3] = n4;
229  v[4] = n5;
230  v[5] = n6;
231  return v;
232  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4,
size_t  n5,
size_t  n6,
size_t  n7 
)
inlinestaticinherited

Definition at line 233 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

236  {
237  std::vector<size_t> v(7);
238  v[0] = n1;
239  v[1] = n2;
240  v[2] = n3;
241  v[3] = n4;
242  v[4] = n5;
243  v[5] = n6;
244  v[6] = n7;
245  return v;
246  }
static std::vector<size_t> stan::io::var_context::to_vec ( size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4,
size_t  n5,
size_t  n6,
size_t  n7,
size_t  n8 
)
inlinestaticinherited

Definition at line 247 of file var_context.hpp.

References make_training::n1, and registry_explorer::v.

250  {
251  std::vector<size_t> v(8);
252  v[0] = n1;
253  v[1] = n2;
254  v[2] = n3;
255  v[3] = n4;
256  v[4] = n5;
257  v[5] = n6;
258  v[6] = n7;
259  v[7] = n8;
260  return v;
261  }
void stan::io::var_context::validate_dims ( const std::string &  stage,
const std::string &  name,
const std::string &  base_type,
const std::vector< size_t > &  dims_declared 
) const
inlineinherited

Definition at line 124 of file var_context.hpp.

References stan::io::var_context::add_vec(), stan::io::var_context::contains_i(), stan::io::var_context::contains_r(), fetch_tb_beamline_files::dims, stan::io::var_context::dims_r(), MECModelEnuComparisons::i, and lem_server::msg.

Referenced by stan::services::util::read_dense_inv_metric(), stan::services::util::read_diag_inv_metric(), and TEST().

127  {
128  bool is_int_type = base_type == "int";
129  if (is_int_type) {
130  if (!contains_i(name)) {
131  std::stringstream msg;
132  msg << (contains_r(name)
133  ? "int variable contained non-int values"
134  : "variable does not exist" )
135  << "; processing stage=" << stage
136  << "; variable name=" << name
137  << "; base type=" << base_type;
138  throw std::runtime_error(msg.str());
139  }
140  } else {
141  if (!contains_r(name)) {
142  std::stringstream msg;
143  msg << "variable does not exist"
144  << "; processing stage=" << stage
145  << "; variable name=" << name
146  << "; base type=" << base_type;
147  throw std::runtime_error(msg.str());
148  }
149  }
150  std::vector<size_t> dims = dims_r(name);
151  if (dims.size() != dims_declared.size()) {
152  std::stringstream msg;
153  msg << "mismatch in number dimensions declared and found in context"
154  << "; processing stage=" << stage
155  << "; variable name=" << name
156  << "; dims declared=";
157  add_vec(msg, dims_declared);
158  msg << "; dims found=";
159  add_vec(msg, dims);
160  throw std::runtime_error(msg.str());
161  }
162  for (size_t i = 0; i < dims.size(); ++i) {
163  if (dims_declared[i] != dims[i]) {
164  std::stringstream msg;
165  msg << "mismatch in dimension declared and found in context"
166  << "; processing stage=" << stage
167  << "; variable name=" << name
168  << "; position="
169  << i
170  << "; dims declared=";
171  add_vec(msg, dims_declared);
172  msg << "; dims found=";
173  add_vec(msg, dims);
174  throw std::runtime_error(msg.str());
175  }
176  }
177  }
const XML_Char * name
Definition: expat.h:151
virtual bool contains_r(const std::string &name) const =0
virtual bool contains_i(const std::string &name) const =0
void add_vec(std::stringstream &msg, const std::vector< size_t > &dims) const
virtual std::vector< size_t > dims_r(const std::string &name) const =0
std::vector<int> stan::io::chained_var_context::vals_i ( const std::string &  name) const
inlinevirtual

Return the integer values for the variable of the specified name in last-index-major order or the empty sequence if the variable is not defined.

Parameters
nameName of variable.
Returns
Sequence of integer values.

Implements stan::io::var_context.

Definition at line 37 of file chained_var_context.hpp.

References stan::io::var_context::contains_i(), and stan::io::var_context::vals_i().

37  {
39  }
const XML_Char * name
Definition: expat.h:151
virtual std::vector< int > vals_i(const std::string &name) const =0
virtual bool contains_i(const std::string &name) const =0
std::vector<double> stan::io::chained_var_context::vals_r ( const std::string &  name) const
inlinevirtual

Return the floating point values for the variable of the specified variable name in last-index-major order. This method should cast integers to floating point values if the values of the named variable are all integers.

If there is no variable of the specified name, the empty vector is returned.

Parameters
nameName of variable.
Returns
Sequence of values for the named variable.

Implements stan::io::var_context.

Definition at line 33 of file chained_var_context.hpp.

References stan::io::var_context::contains_r(), and stan::io::var_context::vals_r().

Referenced by TEST().

33  {
35  }
const XML_Char * name
Definition: expat.h:151
virtual std::vector< double > vals_r(const std::string &name) const =0
virtual bool contains_r(const std::string &name) const =0

Member Data Documentation

const var_context& stan::io::chained_var_context::vc1_
private

Definition at line 17 of file chained_var_context.hpp.

const var_context& stan::io::chained_var_context::vc2_
private

Definition at line 18 of file chained_var_context.hpp.


The documentation for this class was generated from the following file: