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

#include "stan/io/array_var_context.hpp"

Inheritance diagram for stan::io::array_var_context:
stan::io::var_context

Public Member Functions

 array_var_context (const std::vector< std::string > &names_r, const std::vector< double > &values_r, const std::vector< std::vector< size_t > > &dim_r)
 
 array_var_context (const std::vector< std::string > &names_i, const std::vector< int > &values_i, const std::vector< std::vector< size_t > > &dim_i)
 
 array_var_context (const std::vector< std::string > &names_r, const std::vector< double > &values_r, const std::vector< std::vector< size_t > > &dim_r, const std::vector< std::string > &names_i, const std::vector< int > &values_i, const std::vector< std::vector< size_t > > &dim_i)
 
bool contains_r (const std::string &name) const
 
bool contains_i (const std::string &name) const
 
std::vector< double > vals_r (const std::string &name) const
 
std::vector< size_t > dims_r (const std::string &name) const
 
std::vector< intvals_i (const std::string &name) const
 
std::vector< size_t > dims_i (const std::string &name) const
 
virtual void names_r (std::vector< std::string > &names) const
 
virtual void names_i (std::vector< std::string > &names) const
 
bool remove (const std::string &name)
 
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 Member Functions

bool contains_r_only (const std::string &name) const
 
template<typename T >
void validate (const std::vector< std::string > &names, const std::vector< T > &array, const std::vector< std::vector< size_t > > &dims)
 
void add_r (const std::vector< std::string > &names, const std::vector< double > &values, const std::vector< std::vector< size_t > > &dims)
 
void add_i (const std::vector< std::string > &names, const std::vector< int > &values, const std::vector< std::vector< size_t > > &dims)
 

Private Attributes

std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
 
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
 
std::vector< double > const empty_vec_r_
 
std::vector< int > const empty_vec_i_
 
std::vector< size_t > const empty_vec_ui_
 

Detailed Description

An array_var_context object represents a named arrays with dimensions constructed from an array, a vector of names, and a vector of all dimensions for each element.

Definition at line 29 of file array_var_context.hpp.

Constructor & Destructor Documentation

stan::io::array_var_context::array_var_context ( const std::vector< std::string > &  names_r,
const std::vector< double > &  values_r,
const std::vector< std::vector< size_t > > &  dim_r 
)
inline

Construct an array_var_context from only real value arrays.

Parameters
names_rnames for each element
values_ra vector of double values for all elements
dim_ra vector of dimensions

Definition at line 114 of file array_var_context.hpp.

References add_r().

116  {
117  add_r(names_r, values_r, dim_r);
118  }
void add_r(const std::vector< std::string > &names, const std::vector< double > &values, const std::vector< std::vector< size_t > > &dims)
virtual void names_r(std::vector< std::string > &names) const
stan::io::array_var_context::array_var_context ( const std::vector< std::string > &  names_i,
const std::vector< int > &  values_i,
const std::vector< std::vector< size_t > > &  dim_i 
)
inline

Construct an array_var_context from only integer value arrays.

Parameters
names_inames for each element
values_ia vector of integer values for all elements
dim_ia vector of dimensions

Definition at line 127 of file array_var_context.hpp.

References add_i().

129  {
130  add_i(names_i, values_i, dim_i);
131  }
virtual void names_i(std::vector< std::string > &names) const
void add_i(const std::vector< std::string > &names, const std::vector< int > &values, const std::vector< std::vector< size_t > > &dims)
stan::io::array_var_context::array_var_context ( const std::vector< std::string > &  names_r,
const std::vector< double > &  values_r,
const std::vector< std::vector< size_t > > &  dim_r,
const std::vector< std::string > &  names_i,
const std::vector< int > &  values_i,
const std::vector< std::vector< size_t > > &  dim_i 
)
inline

Construct an array_var_context from arrays of both double and integer separately

Definition at line 138 of file array_var_context.hpp.

References add_i(), and add_r().

143  {
144  add_i(names_i, values_i, dim_i);
145  add_r(names_r, values_r, dim_r);
146  }
virtual void names_i(std::vector< std::string > &names) const
void add_r(const std::vector< std::string > &names, const std::vector< double > &values, const std::vector< std::vector< size_t > > &dims)
virtual void names_r(std::vector< std::string > &names) const
void add_i(const std::vector< std::string > &names, const std::vector< int > &values, const std::vector< std::vector< size_t > > &dims)

Member Function Documentation

void stan::io::array_var_context::add_i ( const std::vector< std::string > &  names,
const std::vector< int > &  values,
const std::vector< std::vector< size_t > > &  dims 
)
inlineprivate

Definition at line 90 of file array_var_context.hpp.

References fetch_tb_beamline_files::dims, febshutoff_auto::end, MECModelEnuComparisons::i, stan::io::product(), febshutoff_auto::start, registry_explorer::v, and validate().

Referenced by array_var_context().

92  {
94  size_t start = 0;
95  size_t end = 0;
96  for (size_t i = 0; i < names.size(); i++) {
97  end += product(dims[i]);
98  std::vector<int> v(values.begin() + start, values.begin() + end);
99  vars_i_[names[i]]
100  = std::pair<std::vector<int>,
101  std::vector<size_t> >(v, dims[i]);
102  start = end;
103  }
104  }
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
T product(std::vector< T > dims)
void validate(const std::vector< std::string > &names, const std::vector< T > &array, const std::vector< std::vector< size_t > > &dims)
void stan::io::array_var_context::add_r ( const std::vector< std::string > &  names,
const std::vector< double > &  values,
const std::vector< std::vector< size_t > > &  dims 
)
inlineprivate

Definition at line 75 of file array_var_context.hpp.

References fetch_tb_beamline_files::dims, febshutoff_auto::end, MECModelEnuComparisons::i, stan::io::product(), febshutoff_auto::start, registry_explorer::v, and validate().

Referenced by array_var_context().

77  {
79  size_t start = 0;
80  size_t end = 0;
81  for (size_t i = 0; i < names.size(); i++) {
82  end += product(dims[i]);
83  std::vector<double> v(values.begin() + start, values.begin() + end);
84  vars_r_[names[i]]
85  = std::pair<std::vector<double>,
86  std::vector<size_t> >(v, dims[i]);
87  start = end;
88  }
89  }
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
T product(std::vector< T > dims)
void validate(const std::vector< std::string > &names, const std::vector< T > &array, const std::vector< std::vector< size_t > > &dims)
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::array_var_context::contains_i ( const std::string &  name) const
inlinevirtual

Return true if this dump contains an integer valued array with the specified name.

Parameters
nameVariable name to test.
Returns
true if the variable name has an integer array value.

Implements stan::io::var_context.

Definition at line 168 of file array_var_context.hpp.

Referenced by contains_r(), dims_i(), dims_r(), TEST(), vals_i(), and vals_r().

168  {
169  return vars_i_.find(name) != vars_i_.end();
170  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
bool stan::io::array_var_context::contains_r ( const std::string &  name) const
inlinevirtual

Return true if this dump contains the specified variable name is defined. This method returns true even if the values are all integers.

Parameters
nameVariable name to test.
Returns
true if the variable exists.

Implements stan::io::var_context.

Definition at line 156 of file array_var_context.hpp.

References contains_i(), and contains_r_only().

Referenced by TEST().

156  {
157  return contains_r_only(name) || contains_i(name);
158  }
const XML_Char * name
Definition: expat.h:151
bool contains_i(const std::string &name) const
bool contains_r_only(const std::string &name) const
bool stan::io::array_var_context::contains_r_only ( const std::string &  name) const
inlineprivate

Definition at line 41 of file array_var_context.hpp.

Referenced by contains_r(), dims_r(), and vals_r().

41  {
42  return vars_r_.find(name) != vars_r_.end();
43  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
std::vector<size_t> stan::io::array_var_context::dims_i ( const std::string &  name) const
inlinevirtual

Return the dimensions for the integer variable with the specified name.

Parameters
nameName of variable.
Returns
Dimensions of variable.

Implements stan::io::var_context.

Definition at line 230 of file array_var_context.hpp.

References contains_i(), empty_vec_ui_, and moon_position_table_new3::second.

Referenced by TEST().

230  {
231  if (contains_i(name)) {
232  return (vars_i_.find(name)->second).second;
233  }
234  return empty_vec_ui_;
235  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
bool contains_i(const std::string &name) const
std::vector< size_t > const empty_vec_ui_
std::vector<size_t> stan::io::array_var_context::dims_r ( const std::string &  name) const
inlinevirtual

Return the dimensions for the double variable with the specified name.

Parameters
nameName of variable.
Returns
Dimensions of variable.

Implements stan::io::var_context.

Definition at line 200 of file array_var_context.hpp.

References contains_i(), contains_r_only(), empty_vec_ui_, and moon_position_table_new3::second.

Referenced by TEST().

200  {
201  if (contains_r_only(name)) {
202  return (vars_r_.find(name)->second).second;
203  } else if (contains_i(name)) {
204  return (vars_i_.find(name)->second).second;
205  }
206  return empty_vec_ui_;
207  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
bool contains_i(const std::string &name) const
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
std::vector< size_t > const empty_vec_ui_
bool contains_r_only(const std::string &name) const
virtual void stan::io::array_var_context::names_i ( std::vector< std::string > &  names) const
inlinevirtual

Return a list of the names of the integer variables in the dump.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 259 of file array_var_context.hpp.

References it.

259  {
260  names.resize(0);
261  for (std::map<std::string,
262  std::pair<std::vector<int>,
263  std::vector<size_t> > >
264  ::const_iterator it = vars_i_.begin();
265  it != vars_i_.end(); ++it)
266  names.push_back((*it).first);
267  }
set< int >::iterator it
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
virtual void stan::io::array_var_context::names_r ( std::vector< std::string > &  names) const
inlinevirtual

Return a list of the names of the floating point variables in the dump.

Parameters
namesVector to store the list of names in.

Implements stan::io::var_context.

Definition at line 243 of file array_var_context.hpp.

References it.

243  {
244  names.resize(0);
245  for (std::map<std::string,
246  std::pair<std::vector<double>,
247  std::vector<size_t> > >
248  ::const_iterator it = vars_r_.begin();
249  it != vars_r_.end(); ++it)
250  names.push_back((*it).first);
251  }
set< int >::iterator it
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool stan::io::array_var_context::remove ( const std::string &  name)
inline

Remove variable from the object.

Parameters
nameName of the variable to remove.
Returns
If variable is removed returns true, else returns false.

Definition at line 276 of file array_var_context.hpp.

276  {
277  return (vars_i_.erase(name) > 0)
278  || (vars_r_.erase(name) > 0);
279  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
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  }
template<typename T >
void stan::io::array_var_context::validate ( const std::vector< std::string > &  names,
const std::vector< T > &  array,
const std::vector< std::vector< size_t > > &  dims 
)
inlineprivate

Check (1) if the vecotr size of dimensions is no smaller than the name vecotr size; (2) if the size of the input array is large enough for what is needed.

Definition at line 51 of file array_var_context.hpp.

References fetch_tb_beamline_files::dims, MECModelEnuComparisons::i, stan::math::invalid_argument(), lem_server::msg, stan::io::product(), and produceInfoGainMatrix::total.

Referenced by add_i(), and add_r().

53  {
54  size_t total = 0;
55  size_t num_par = names.size();
56  if (num_par > dims.size()) {
57  std::stringstream msg;
58  msg << "size of vector of dimensions (found " << dims.size() << ") "
59  << "should be no smaller than number of parameters (found "
60  << num_par << ").";
61  BOOST_THROW_EXCEPTION(std::invalid_argument(msg.str()));
62  }
63  for (size_t i = 0; i < num_par; i++)
64  total += stan::io::product(dims[i]);
65  size_t array_len = array.size();
66  if (total > array_len) {
67  std::stringstream msg;
68  msg << "array is not long enough for all elements: " << array_len
69  << " is found, but "
70  << total << " is needed.";
71  BOOST_THROW_EXCEPTION(std::invalid_argument(msg.str()));
72  }
73  }
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
T product(std::vector< T > dims)
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::array_var_context::vals_i ( const std::string &  name) const
inlinevirtual

Return the integer values for the variable with the specified name.

Parameters
nameName of variable.
Returns
Values.

Implements stan::io::var_context.

Definition at line 216 of file array_var_context.hpp.

References contains_i(), and empty_vec_i_.

Referenced by TEST().

216  {
217  if (contains_i(name)) {
218  return (vars_i_.find(name)->second).first;
219  }
220  return empty_vec_i_;
221  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
std::vector< int > const empty_vec_i_
bool contains_i(const std::string &name) const
std::vector<double> stan::io::array_var_context::vals_r ( const std::string &  name) const
inlinevirtual

Return the double values for the variable with the specified name or null.

Parameters
nameName of variable.
Returns
Values of variable.

Implements stan::io::var_context.

Definition at line 179 of file array_var_context.hpp.

References contains_i(), contains_r_only(), and empty_vec_r_.

Referenced by TEST().

179  {
180  if (contains_r_only(name)) {
181  return (vars_r_.find(name)->second).first;
182  } else if (contains_i(name)) {
183  std::vector<int> vec_int = (vars_i_.find(name)->second).first;
184  std::vector<double> vec_r(vec_int.size());
185  for (size_t ii = 0; ii < vec_int.size(); ii++) {
186  vec_r[ii] = vec_int[ii];
187  }
188  return vec_r;
189  }
190  return empty_vec_r_;
191  }
const XML_Char * name
Definition: expat.h:151
std::map< std::string, std::pair< std::vector< int >, std::vector< size_t > > > vars_i_
bool contains_i(const std::string &name) const
std::map< std::string, std::pair< std::vector< double >, std::vector< size_t > > > vars_r_
bool contains_r_only(const std::string &name) const
std::vector< double > const empty_vec_r_

Member Data Documentation

std::vector<int> const stan::io::array_var_context::empty_vec_i_
private

Definition at line 38 of file array_var_context.hpp.

Referenced by vals_i().

std::vector<double> const stan::io::array_var_context::empty_vec_r_
private

Definition at line 37 of file array_var_context.hpp.

Referenced by vals_r().

std::vector<size_t> const stan::io::array_var_context::empty_vec_ui_
private

Definition at line 39 of file array_var_context.hpp.

Referenced by dims_i(), and dims_r().

std::map<std::string, std::pair<std::vector<int>, std::vector<size_t> > > stan::io::array_var_context::vars_i_
private

Definition at line 36 of file array_var_context.hpp.

std::map<std::string, std::pair<std::vector<double>, std::vector<size_t> > > stan::io::array_var_context::vars_r_
private

Definition at line 33 of file array_var_context.hpp.


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