SG++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sgpp::optimization::file_io Namespace Reference

Namespace with functions to write data (vectors, matrices, grids, ...) to a file. More...

Functions

template<>
const char * getTypeString (const std::vector< uint8_t > &A)
 
template<>
const char * getTypeString (const std::vector< uint16_t > &A)
 
template<>
const char * getTypeString (const std::vector< uint32_t > &A)
 
template<>
const char * getTypeString (const std::vector< uint64_t > &A)
 
template<>
const char * getTypeString (const std::vector< float > &A)
 
template<>
const char * getTypeString (const std::vector< double > &A)
 
template<class T >
const char * getTypeString (const std::vector< T > &A)
 
template<>
const char * getTypeString (const std::vector< std::string > &A)
 
template<>
void readEntry (std::ifstream &f, std::string &entry)
 Read string from input stream (called by readMatrix()). More...
 
template<class T >
void readEntry (std::ifstream &f, T &entry)
 Read bytes of entry representation from input stream (called by readMatrix()). More...
 
void readGrid (const std::string &filename, base::GridStorage &gridStorage)
 Read a grid (only grid points) from a file. More...
 
void readGrid (const std::string &filename, base::GridStorage &gridStorage, base::DataVector &functionValues)
 Read a grid (grid points and function values) from a file. More...
 
void readMatrix (const std::string &filename, base::DataMatrix &A)
 Read a matrix from a file. More...
 
template<class T >
void readMatrix (const std::string &filename, std::vector< T > &A, size_t &m, size_t &n)
 Read a matrix (stored row-wise in a std::vector) from a file. More...
 
void readVector (const std::string &filename, base::DataVector &x)
 Read a base::DataVector from a file. More...
 
template<class T >
void readVector (const std::string &filename, std::vector< T > &x)
 Read a std::vector from a file. More...
 
template<>
void writeEntry (std::ofstream &f, const std::string &entry)
 Write string to output stream (called by writeMatrix()). More...
 
template<class T >
void writeEntry (std::ofstream &f, const T &entry)
 Write bytes of entry representation to output stream (called by writeMatrix()). More...
 
void writeGrid (const std::string &filename, const base::GridStorage &gridStorage)
 Write a grid (only grid points) to a file. More...
 
void writeGrid (const std::string &filename, const base::GridStorage &gridStorage, const base::DataVector &functionValues)
 Write a grid (grid points and function values) to a file. More...
 
void writeMatrix (const std::string &filename, base::DataMatrix &A)
 Write a base::DataMatrix to a file. More...
 
template<class T >
void writeMatrix (const std::string &filename, const std::vector< T > &A, size_t m, size_t n)
 Write a matrix (stored row-wise in a std::vector) to a file. More...
 
void writeVector (const std::string &filename, base::DataVector &x)
 Write a base::DataVector to a file. More...
 
template<class T >
void writeVector (const std::string &filename, const std::vector< T > &x)
 Write a std::vector to a file. More...
 

Detailed Description

Namespace with functions to write data (vectors, matrices, grids, ...) to a file.

Function Documentation

template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< uint8_t > &  A)
Parameters
Aignored
Returns
type string for uint8_t (right-padded "uint8")

Referenced by readMatrix(), and writeMatrix().

template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< uint16_t > &  A)
Parameters
Aignored
Returns
type string for uint16_t (right-padded "uint16")
template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< uint32_t > &  A)
Parameters
Aignored
Returns
type string for uint32_t (right-padded "uint32")
template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< uint64_t > &  A)
Parameters
Aignored
Returns
type string for uint64_t (right-padded "uint64")
template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< float > &  A)
Parameters
Aignored
Returns
type string for float (right-padded "float")
template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< double > &  A)
Parameters
Aignored
Returns
type string for double (right-padded "double")
template<class T >
const char* sgpp::optimization::file_io::getTypeString ( const std::vector< T > &  A)
Parameters
Aignored
Returns
type string for unknown types (right-padded "other")
template<>
const char * sgpp::optimization::file_io::getTypeString ( const std::vector< std::string > &  A)
Parameters
Aignored
Returns
type string for string (right-padded "string")
template<>
void sgpp::optimization::file_io::readEntry ( std::ifstream &  f,
std::string &  entry 
)

Read string from input stream (called by readMatrix()).

Parameters
finput stream to be read
[out]entryentry to be read

Referenced by readMatrix().

template<class T >
void sgpp::optimization::file_io::readEntry ( std::ifstream &  f,
T &  entry 
)

Read bytes of entry representation from input stream (called by readMatrix()).

Parameters
finput stream to be read
[out]entryentry to be read
void sgpp::optimization::file_io::readGrid ( const std::string &  filename,
base::GridStorage &  gridStorage 
)

Read a grid (only grid points) from a file.

The format is as in writeGrid (discarding function values).

Parameters
filenamefilename of the file to be read
[out]gridStoragegrid storage containing the grid points
void sgpp::optimization::file_io::readGrid ( const std::string &  filename,
base::GridStorage &  gridStorage,
base::DataVector &  functionValues 
)

Read a grid (grid points and function values) from a file.

The format is as in writeGrid.

Parameters
filenamefilename of the file to be read
[out]gridStoragegrid storage containing the grid points
[out]functionValuesvector of function values

References sgpp::base::HashGridStorage::clear(), f, sgpp::base::HashGridStorage::insert(), sgpp::base::DataVector::resize(), and sgpp::base::HashGridPoint::set().

void sgpp::optimization::file_io::readMatrix ( const std::string &  filename,
base::DataMatrix &  A 
)

Read a matrix from a file.

The format is as in writeMatrix.

Parameters
filenamefilename of the file to be read
[out]Amatrix

References m, and sgpp::base::DataMatrix::resize().

Referenced by readVector().

template<class T >
void sgpp::optimization::file_io::readMatrix ( const std::string &  filename,
std::vector< T > &  A,
size_t &  m,
size_t &  n 
)

Read a matrix (stored row-wise in a std::vector) from a file.

The format is as in writeMatrix.

Parameters
filenamefilename of the file to be written
[out]Amatrix
[out]mnumber of rows
[out]nnumber of columns

References f, getTypeString(), and readEntry().

void sgpp::optimization::file_io::readVector ( const std::string &  filename,
base::DataVector &  x 
)

Read a base::DataVector from a file.

It's readMatrix with the vector as one row.

Parameters
filenamefilename of the file to be read
[out]xvector

References m, readMatrix(), and sgpp::base::DataVector::resize().

template<class T >
void sgpp::optimization::file_io::readVector ( const std::string &  filename,
std::vector< T > &  x 
)

Read a std::vector from a file.

It's readMatrix with the vector as one row.

Parameters
filenamefilename of the file to be read
[out]xvector

References m, and readMatrix().

template<>
void sgpp::optimization::file_io::writeEntry ( std::ofstream &  f,
const std::string &  entry 
)

Write string to output stream (called by writeMatrix()).

Parameters
foutput stream to be written to
entryentry to be written

Referenced by writeMatrix().

template<class T >
void sgpp::optimization::file_io::writeEntry ( std::ofstream &  f,
const T &  entry 
)

Write bytes of entry representation to output stream (called by writeMatrix()).

Parameters
foutput stream to be written to
entryentry to be written
void sgpp::optimization::file_io::writeGrid ( const std::string &  filename,
const base::GridStorage &  gridStorage 
)

Write a grid (only grid points) to a file.

The format is the same as the version with functions values with all function values set to zero.

Parameters
filenamefilename of the file to be written
gridStoragegrid storage containing the grid points

References sgpp::base::HashGridStorage::getSize().

void sgpp::optimization::file_io::writeGrid ( const std::string &  filename,
const base::GridStorage &  gridStorage,
const base::DataVector &  functionValues 
)

Write a grid (grid points and function values) to a file.

The format is as follows:

size_t   N (number of grid points)
size_t   d (dimension)
for j = 0, ..., N-1
    for t = 0, ..., d-1
        double           grid_point[j].coord(t)
        unsigned int     grid_point[j].level(t)
        unsigned int     grid_point[j].index(t)
    end
    double   function_value[j]
end
Parameters
filenamefilename of the file to be written
gridStoragegrid storage containing the grid points
functionValuesvector of function values

References f, sgpp::base::HashGridStorage::getCoordinate(), sgpp::base::HashGridStorage::getDimension(), sgpp::base::HashGridPoint::getIndex(), sgpp::base::HashGridPoint::getLevel(), sgpp::base::HashGridStorage::getSize(), and sgpp::base::DataVector::getSize().

void sgpp::optimization::file_io::writeMatrix ( const std::string &  filename,
base::DataMatrix &  A 
)

Write a base::DataMatrix to a file.

Parameters
filenamefilename of the file to be written
Amatrix

References sgpp::base::DataMatrix::getNcols(), sgpp::base::DataMatrix::getNrows(), and sgpp::base::DataMatrix::getPointer().

Referenced by writeVector().

template<class T >
void sgpp::optimization::file_io::writeMatrix ( const std::string &  filename,
const std::vector< T > &  A,
size_t  m,
size_t  n 
)

Write a matrix (stored row-wise in a std::vector) to a file.

The format is as follows:

size_t       m
size_t       n
char[16]     type string (one of "uint8", "uint16", "uint32",
             "uint64", "double", "string", or "other",
             right-padded with spaces to 16 characters)
for i = 0, ..., m*n - 1
    T        A[i] (size depending on template parameter,
             strings are written null-terminatedly)
end
Parameters
filenamefilename of the file to be written
Amatrix
mnumber of rows
nnumber of columns

References f, getTypeString(), and writeEntry().

void sgpp::optimization::file_io::writeVector ( const std::string &  filename,
base::DataVector &  x 
)

Write a base::DataVector to a file.

It's writeMatrix with the vector as one row.

Parameters
filenamefilename of the file to be written
xvector

References sgpp::base::DataVector::getPointer(), sgpp::base::DataVector::getSize(), and writeMatrix().

template<class T >
void sgpp::optimization::file_io::writeVector ( const std::string &  filename,
const std::vector< T > &  x 
)

Write a std::vector to a file.

It's writeMatrix with the vector as one row.

Parameters
filenamefilename of the file to be written
xvector

References writeMatrix().