SG++-Doxygen-Documentation
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

◆ getTypeString() [1/8]

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 getTypeString(), readMatrix(), and writeMatrix().

◆ getTypeString() [2/8]

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")

◆ getTypeString() [3/8]

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")

◆ getTypeString() [4/8]

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")

◆ getTypeString() [5/8]

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

◆ getTypeString() [6/8]

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

◆ getTypeString() [7/8]

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")

References python.utils.converter::filename, getTypeString(), python.utils.sg_projections::gridStorage, readGrid(), writeGrid(), and writeMatrix().

◆ getTypeString() [8/8]

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

◆ readEntry() [1/2]

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 readEntry(), and readMatrix().

◆ readEntry() [2/2]

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

References readEntry().

◆ readGrid() [1/2]

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

Referenced by getTypeString().

◆ readGrid() [2/2]

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(), python.statsfileInfo::f, python.statsfileInfo::i, sgpp::base::HashGridStorage::insert(), python.utils.statsfile2gnuplot::j, parabola::N, and sgpp::base::HashGridPoint::set().

◆ readMatrix() [1/2]

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(), and writeMatrix().

◆ readMatrix() [2/2]

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 python.statsfileInfo::f, getTypeString(), python.statsfileInfo::i, readEntry(), create_dataset::type, and writeVector().

◆ readVector() [1/2]

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, and readMatrix().

Referenced by writeVector().

◆ readVector() [2/2]

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().

◆ writeEntry() [1/2]

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 writeEntry(), and writeMatrix().

◆ writeEntry() [2/2]

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

References python.statsfileInfo::f, and writeEntry().

◆ writeGrid() [1/2]

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(), and parabola::N.

Referenced by getTypeString().

◆ writeGrid() [2/2]

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 python.statsfileInfo::f, sgpp::base::HashGridStorage::getCoordinate(), sgpp::base::HashGridStorage::getDimension(), sgpp::base::HashGridPoint::getIndex(), sgpp::base::HashGridPoint::getLevel(), sgpp::base::HashGridStorage::getSize(), sgpp::base::DataVector::getSize(), python.statsfileInfo::i, python.utils.statsfile2gnuplot::j, and parabola::N.

◆ writeMatrix() [1/2]

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 getTypeString(), and writeVector().

◆ writeMatrix() [2/2]

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 python.statsfileInfo::f, getTypeString(), python.statsfileInfo::i, readMatrix(), create_dataset::type, and writeEntry().

◆ writeVector() [1/2]

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().

Referenced by readMatrix().

◆ writeVector() [2/2]

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 readVector(), and writeMatrix().