![]() |
Stan
2.10.0
probability, sampling & optimization
|
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... | |
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.
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> | 'struct' '(' seq<T> ',' ".Dim" '=' seq<int> ')'
seq<int> ::= int ':' int | cseq<int>
seq<double> ::= cseq<double>
cseq<T> ::= 'c' '(' T % ',' ')'
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |