Stan  2.14.0
probability, sampling & optimization
Public Member Functions | List of all members
stan::io::dump_reader Class Reference

Reads data from S-plus dump format. More...

#include <dump.hpp>

Public Member Functions

 dump_reader (std::istream &in)
 Construct a reader for the specified input stream. More...
 
 ~dump_reader ()
 Destroy this reader. More...
 
std::string name ()
 Return the name of the most recently read variable. More...
 
std::vector< size_t > dims ()
 Return the dimensions of the most recently read variable. More...
 
bool is_int ()
 Checks if the last item read is integer. More...
 
std::vector< int > int_values ()
 Returns the integer values from the last item if the last item read was an integer and the empty vector otherwise. More...
 
std::vector< double > double_values ()
 Returns the floating point values from the last item if the last item read contained floating point values and the empty vector otherwise. More...
 
bool next ()
 Read the next value from the input stream, returning true if successful and false if no further input may be read. More...
 

Detailed Description

Reads data from S-plus dump format.

A dump_reader parses data from the S-plus dump format, a human-readable ASCII representation of arbitrarily dimensioned arrays of integers and arrays of floating point values.

Stan's dump reader is limited to reading integers, scalars and arrays of arbitrary dimensionality of integers and scalars. It is able to read from a file consisting of a sequence of dumped variables.

There cannot be any NA (i.e., undefined) values, because these cannot be represented as double values.

The dump reader class follows a standard scanner pattern. The method next() is called to scan the next input. The type, dimensions, and values of the input is then available through method calls. Here, the type is either double or integer, and the values are the name of the variable and its array of values. If there is a single value, the dimension array is empty. For a list, the dimension array contains a single entry for the number of values. For an array, the dimensions are the dimensions of the array.

Reads are performed in an "S-compatible" mode whereby a string such as "1" or "-127" denotes and integer, whereas a string such as "1." or "0.9e-5" represents a floating point value.

The dump reader treats "integer(x)" as an array of zeros (type being integer and length x), where x any non-negative integers and x can be omitted to indicate zero-length. So the following are all legitimate: * "x <- integer()", "x <- integer(0) ", and "x <- integer(3)". For array of zeros of type double, we can replace the above "integer" with "double". This is mainly for the purpose of supporting zero-size arrays such as "x <- structure(integer(0), .Dim = c(2, 0))".

For dumping, arrays are indexed in last-index major fashion, which corresponds to column-major order for matrices represented as two-dimensional arrays. As a result, the first indices change fastest. For instance, if there is an three-dimensional array x with dimensions [2,2,2], then there are 8 values, provided in the order

[0,0,0], [1,0,0], [0,1,0], [1,1,0], [0,0,1], [1,0,1], [0,1,1], [1,1,1].

definitions ::= definition+

definition ::= name ("<-" | '=') value optional_semicolon

name ::= char* | ''' char* ''' | '"' char* '"'

value ::= value<int> | value<double>

value<T> ::= T | seq<T> | zero_array<T> | "structure" '(' seq<T> ',' ".Dim" '=' seq<int> ')' | "structure" '(' zero_array<T> ',' ".Dim" '=' seq<int> ')'

seq<int> ::= int ':' int | cseq<int>

seq<double> ::= cseq<double>

cseq<T> ::= 'c' '(' vseq<T> ')'

vseq<T> ::= T | T ',' vseq<T>

zero_array<integer> ::= "integer"<non negative int?>

zero_array<double> ::= "double"<non negative int?>

Definition at line 116 of file dump.hpp.

Constructor & Destructor Documentation

§ dump_reader()

stan::io::dump_reader::dump_reader ( std::istream &  in)
inlineexplicit

Construct a reader for the specified input stream.

Parameters
inInput stream reference from which to read.

Definition at line 488 of file dump.hpp.

§ ~dump_reader()

stan::io::dump_reader::~dump_reader ( )
inline

Destroy this reader.

Definition at line 493 of file dump.hpp.

Member Function Documentation

§ dims()

std::vector<size_t> stan::io::dump_reader::dims ( )
inline

Return the dimensions of the most recently read variable.

Returns
Last dimensions.

Definition at line 511 of file dump.hpp.

§ double_values()

std::vector<double> stan::io::dump_reader::double_values ( )
inline

Returns the floating point values from the last item if the last item read contained floating point values and the empty vector otherwise.

Returns
Floating point values of last item.

Definition at line 544 of file dump.hpp.

§ int_values()

std::vector<int> stan::io::dump_reader::int_values ( )
inline

Returns the integer values from the last item if the last item read was an integer and the empty vector otherwise.

Returns
Integer values of last item.

Definition at line 533 of file dump.hpp.

§ is_int()

bool stan::io::dump_reader::is_int ( )
inline

Checks if the last item read is integer.

Return true if the value(s) in the most recently read item are integer values and false if they are floating point.

Definition at line 522 of file dump.hpp.

§ name()

std::string stan::io::dump_reader::name ( )
inline

Return the name of the most recently read variable.

Returns
Name of most recently read variable.

Definition at line 501 of file dump.hpp.

§ next()

bool stan::io::dump_reader::next ( )
inline

Read the next value from the input stream, returning true if successful and false if no further input may be read.

Returns
Return true if a fresh variable was read.
Exceptions
bad_castif bad number values encountered.

Definition at line 556 of file dump.hpp.


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

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