|
Theoretica
Mathematical Library
|
Input and output module. More...
Classes | |
| class | hdf5_file |
| High-level interface for managing an HDF5 file, its structure, and operations. More... | |
| class | hdf5_handle |
| RAII wrapper for managing HDF5 C-style handles, allowing direct API usage. More... | |
| class | hdf5_node |
| Represents a single node (group or dataset) in the HDF5 file hierarchy. More... | |
Enumerations | |
| enum class | IoError : int { None = 0x00 , FileNotFound = 0x01 , PermissionDenied = 0x02 , ReadError = 0x04 , WriteError = 0x08 , FormatError = 0x10 , EndOfFile = 0x20 } |
| IO error enumeration. More... | |
| enum class | HDF5NodeType { UNKNOWN , GROUP , DATASET } |
| Type of node inside an HDF5 file. More... | |
Functions | |
| std::vector< std::string > | parse_csv (const std::string &line, char delimiter=',') |
| Parse a CSV line handling quoted fields. | |
| std::string | quote_csv (const std::string &str) |
| Given a string entry, sanitize it for printing to a CSV file. | |
| template<typename Type , unsigned int N> | |
| void | write_csv (const std::string &filename, const vec< Type, N > &v, unsigned int precision=8) |
| Write a vector to file in the CSV format. | |
| template<typename Type , unsigned int N> | |
| void | write_csv (const std::string &filename, const std::string &header, const vec< Type, N > &v, unsigned int precision=8) |
| Write a vector to file in the CSV format, with a column header. | |
| template<typename Type , unsigned int N, enable_real< Type > = true> | |
| void | read_csv (const std::string &filename, vec< Type, N > &v) |
| Read a vector from a file in the CSV format. | |
| template<typename Type , unsigned int N, enable_real< Type > = true> | |
| void | read_csv (const std::string &filename, const std::string &col_name, vec< Type, N > &v, bool trim_nan=true) |
| Read a specific column of a CSV file as a vector. | |
| template<typename Type , unsigned int N, unsigned int M> | |
| void | write_csv (const std::string &filename, const mat< Type, N, M > &A, const std::string &delimiter=", ", unsigned int precision=8) |
| Write a matrix to file in the CSV format. | |
| template<unsigned int N, unsigned int K> | |
| void | read_csv (const std::string &filename, mat< real, N, K > &A) |
| Read a matrix from a file in the CSV format. | |
| void | write_csv (const std::string &filename, const data_table &table, const std::string &delimiter=", ", unsigned int precision=8) |
| Write a data_table to file in the CSV format. | |
| void | read_csv (const std::string &filename, data_table &table) |
| Read a data_table from a file in the CSV format. | |
| void | write_csv (const std::string &filename, const histogram &hist, bool normalized=false, bool lower_extreme=false, const std::string &delimiter=", ", unsigned int precision=8) |
| Write histogram data to file in the CSV format. | |
| void | read_csv (const std::string &filename, histogram &hist, bool lower_extreme=false) |
| Read a histogram from file, expecting a CSV format with columns "bins", "counts", "number", "average", "tss", "min" and "max", as written by write_csv(histogram). | |
| template<typename Type > | |
| Type | read_csv (const std::string &filename) |
| Read a generic data structure from a file in the CSV format, specifying the target type. | |
| int | to_errno (IoError err) |
| Convert an IoError class enum to conventional errno codes. | |
| const char * | to_cstring (IoError err) |
| Convert an IoError class enum to a string description. | |
| std::string | to_string (const hdf5_node &node) |
| Generates a string representation of the HDF5 tree structure. | |
| std::ostream & | operator<< (std::ostream &os, const hdf5_node &node) |
| Prints the HDF5 file tree to a stream. | |
| hdf5_handle | hdf5_open (const std::string &filename, bool write=false) |
| Open an HDF5 file with the given filename, returning a file handle. | |
| bool | hdf5_is_valid (const hdf5_handle &handle) |
| Check whether a given HDF5 handle is valid. | |
| hdf5_node | hdf5_load (const hdf5_handle &id) |
| Recursively loads the structure of an active HDF5 group or file. | |
| void | hdf5_create_group (const hdf5_handle &id, const std::string &path) |
| Create a new group at the given path under an already open HDF5 location. | |
| void | hdf5_delete_group (const hdf5_handle &id, const std::string &path) |
| Delete a group (link) at the given path under an already open HDF5 location. | |
| template<typename Type > | |
| Type | hdf5_read_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name) |
| Reads an attribute attached to a specific node. | |
| void | hdf5_delete_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name) |
| Deletes an attribute attached to a specific node, if it exists. | |
| template<typename Type > | |
| void | hdf5_write_attribute (const hdf5_handle &id, const std::string &path, const std::string &attr_name, const Type &value) |
| Writes or overwrites an attribute attached to a specific node. | |
| template<typename Vector = vec<real>> | |
| Vector & | hdf5_read_vec (const hdf5_handle &id, const std::string &path, Vector &v) |
| Loads a 1D dataset array into a vector. | |
| template<typename Vector = vec<real>> | |
| Vector | hdf5_read_vec (const hdf5_handle &id, const std::string &path) |
| Loads a 1D dataset array into a vector. | |
| template<typename Vector > | |
| void | hdf5_write_vec (const hdf5_handle &id, const std::string &path, const Vector &v) |
| Writes a 1D vector to an HDF5 dataset, overwriting if it exists. | |
| void | hdf5_delete_dataset (const hdf5_handle &id, const std::string &path) |
| Deletes a dataset at the given path if it exists. | |
| template<typename Matrix = mat<real>> | |
| Matrix | hdf5_read_mat (const hdf5_handle &id, const std::string &path, Matrix &m) |
| Loads a 2D dataset array into a matrix. | |
| template<typename Matrix = mat<real>> | |
| Matrix | hdf5_read_mat (const hdf5_handle &id, const std::string &path) |
| Loads a 2D dataset array into a matrix. | |
| template<typename Matrix > | |
| void | hdf5_write_mat (const hdf5_handle &id, const std::string &path, const Matrix &m) |
| Writes a 2D matrix to an HDF5 dataset, overwriting if it exists. | |
| template<typename Type > | |
| void | print (const Type &curr) |
| Print the given argument to standard output. | |
| template<typename Type , typename ... Args> | |
| void | print (const Type &curr, Args... args) |
| Print the given arguments to standard output separated by a space. | |
| void | println () |
| Print a newline to standard output. | |
| template<typename Type > | |
| void | println (const Type &curr) |
| Print the given argument to standard output followed by a newline. | |
| template<typename Type , typename ... Args> | |
| void | println (const Type &curr, Args... args) |
| Print the given arguments to standard output separated by a space and followed by a newline. | |
| std::string | readln () |
| Read a line from standard input, up to a line return. | |
| template<typename Type > | |
| void | readln (Type &last) |
| Read a single object from standard input, ended by a line return. | |
| template<typename Type , typename ... Args> | |
| void | readln (Type &curr, Args &... args) |
| Read objects from standard input, ended by a line return. | |
| bool | is_number (const std::string &str) |
| Check if a given string could be correctly interpreted as a number. | |
| std::string | trim (const std::string &str) |
| Remove all leading and trailing whitespace from a string, returning the resulting string. | |
| std::string | unquote (const std::string &str) |
| Remove leading and trailing double quotes from a string, if both are present. | |
Input and output module.
|
strong |
IO error enumeration.
|
inline |
Create a new group at the given path under an already open HDF5 location.
| id | Open HDF5 file/group identifier. |
| path | Absolute or relative group path to create. |
|
inline |
Deletes an attribute attached to a specific node, if it exists.
| id | The active file handle |
| path | Internal path to the node |
| attr_name | Name of the attribute to delete |
|
inline |
Deletes a dataset at the given path if it exists.
| id | The active file handle |
| path | Internal path to the dataset |
|
inline |
Delete a group (link) at the given path under an already open HDF5 location.
| id | Open HDF5 file/group identifier. |
| path | Absolute or relative group path to delete. |
|
inline |
Check whether a given HDF5 handle is valid.
| handle | The HDF5 handle to check |
|
inline |
Recursively loads the structure of an active HDF5 group or file.
| id | The open HDF5 handle representing the search root |
|
inline |
Open an HDF5 file with the given filename, returning a file handle.
| filename | The path to the HDF5 file |
| write | Whether to open the file with write permissions, creating it if it doesn't exist (defaults to false). |
|
inline |
Reads an attribute attached to a specific node.
| Type | The expected scalar type or std::string |
| id | The active file handle |
| path | Internal path to the node |
| attr_name | Name of the attribute to read |
|
inline |
Loads a 2D dataset array into a matrix.
| Matrix | The matrix container type (defaults to mat<real>). |
| id | The active file handle |
| path | Internal path to the dataset |
|
inline |
Loads a 2D dataset array into a matrix.
| Matrix | The matrix container type (defaults to mat<real>). |
| id | The active file handle |
| path | Internal path to the dataset |
|
inline |
Loads a 1D dataset array into a vector.
| Vector | The vector container type (defaults to vec<real>). |
| id | The active file handle |
| path | Internal path to the dataset |
|
inline |
Loads a 1D dataset array into a vector.
| Vector | The vector container type (defaults to vec<real>). |
| id | The active file handle |
| path | Internal path to the dataset |
|
inline |
Writes or overwrites an attribute attached to a specific node.
| Type | The scalar type or std::string of the metadata |
| id | The active file handle |
| path | Internal path to the node |
| attr_name | Name of the attribute |
| value | The value to write |
|
inline |
Writes a 2D matrix to an HDF5 dataset, overwriting if it exists.
| Matrix | A generic matrix type. Must support .rows(), .cols(), and .data(). |
| id | The active file handle |
| path | Internal path to place the dataset |
| m | The matrix data |
|
inline |
Writes a 1D vector to an HDF5 dataset, overwriting if it exists.
| Vector | The vector container type. |
| id | The active file handle |
| path | Internal path to place the dataset |
| v | The vector data |
Check if a given string could be correctly interpreted as a number.
| str | The string to check |
Prints the HDF5 file tree to a stream.
| os | The output stream |
| node | The target node |
|
inline |
Parse a CSV line handling quoted fields.
Supports fields enclosed in double quotes, with delimiters (commas) inside quoted fields. Does not support escaped quotes or multiline fields.
| line | The CSV line to parse |
| delimiter | The field delimiter (default is comma) |
|
inline |
Given a string entry, sanitize it for printing to a CSV file.
If it contains commas or whitespace, quotes are added before and after the string.
| str | The string to check for relevant characters. |
Read a generic data structure from a file in the CSV format, specifying the target type.
Supported types include vec<> and mat<>.
| filename | The name of the file |
| Type | The type of the data structure to read |
|
inline |
Read a specific column of a CSV file as a vector.
Enables reading a single column from a CSV file which may contain multiple. The file is expected to have a header row, and the column is identified by its header name. If the column is not found, the vector is filled with NaN.
| filename | The name of the file |
| v | A reference to the vector to overwrite |
| col_name | The header name of the column |
| trim_nan | If true, trailing NaN values are trimmed from the vector (default is true). In a larger dataset, it may happen that other columns are longer than the picked one, and so its missing values are filled with NaN. |
|
inline |
Read a data_table from a file in the CSV format.
| filename | The name of the file |
| table | A reference to the data_table to overwrite If present, the header is read as column names. If the file has fewer rows than the data_table, the remaining rows are filled with NaN. |
|
inline |
Read a histogram from file, expecting a CSV format with columns "bins", "counts", "number", "average", "tss", "min" and "max", as written by write_csv(histogram).
| filename | |
| hist |
Read a matrix from a file in the CSV format.
| filename | The name of the file |
| A | A reference to the matrix to overwrite If present, the header is ignored. If the file has fewer rows or columns than the matrix, the remaining elements are filled with NaN. |
Read a vector from a file in the CSV format.
| filename | The name of the file |
| v | A reference to the vector to overwrite |
If present, the header is ignored. If the file has fewer elements than the vector, the remaining elements are filled with NaN.
|
inline |
Read a line from standard input, up to a line return.
Read objects from standard input, ended by a line return.
The object needs to support streaming from an std::istream.
For example, calling readln(x1, x2, x3) reads a line of the form: "1.0 2.0 3.0\n" into variables x1, x2 and x3.
Read a single object from standard input, ended by a line return.
The object needs to support streaming from an std::istream.
Generates a string representation of the HDF5 tree structure.
| node | The node to stringify (along its children) |
|
inline |
Remove all leading and trailing whitespace from a string, returning the resulting string.
| str | The input string |
|
inline |
Remove leading and trailing double quotes from a string, if both are present.
| str | The input string |
|
inline |
Write a data_table to file in the CSV format.
| filename | The name of the file |
| table | The data_table to write |
|
inline |
Write histogram data to file in the CSV format.
| filename | The name of the file |
| histogram | The histogram to save |
| normalized | Whether to write bin counts as frequency (defaults to false) |
| lower_extreme | Whether to write the lower extreme of each bin instead of the midpoint (defaults to false). |
The CSV file will contain a column "bins" containing the midpoint coordinate of each bin (or the lower extreme, if lower_extreme is true), a column "counts" containing the corresponding bin counts (or frequency, if normalized is true) and additional columns with the histogram statistics: "number", "average", "tss", "min" and "max".
|
inline |
Write a matrix to file in the CSV format.
| filename | The name of the file |
| A | The matrix to write |
|
inline |
Write a vector to file in the CSV format, with a column header.
| filename | The name of the file |
| v | The vector to write |
| header | The header to add for the vector column |