Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
|
A class to read file data to matrix and to write file data to a matrix. More...
#include <MatrixIO.h>
Public Member Functions | |
MatrixIO (const std::filesystem::path &path, char separator=',', txeo::Logger &logger=txeo::LoggerConsole::instance()) | |
Constructs MatrixIO object. | |
std::filesystem::path | path () const |
char | separator () const |
template<typename T > | |
txeo::Matrix< T > | read_text_file (bool has_header=false) const |
Returns a matrix with elements read from a text file. | |
template<typename T > | |
void | write_text_file (const txeo::Matrix< T > &matrix) const |
Writes a matrix to a text file. | |
template<typename T > requires (std::is_floating_point_v<T>) | |
void | write_text_file (const txeo::Matrix< T > &matrix, size_t precision) const |
Writes a floating-point matrix with specified precision to a text file. | |
Static Public Member Functions | |
template<typename T > | |
static txeo::Matrix< T > | read_textfile (const std::filesystem::path &path, char separator=',', bool has_header=false) |
Returns a matrix with elements read from a text file. | |
template<typename T > | |
static void | write_textfile (const txeo::Matrix< T > &matrix, const std::filesystem::path &path, char separator=',') |
Writes a matrix to a text file. | |
template<typename T > requires (std::is_floating_point_v<T>) | |
static void | write_textfile (const txeo::Matrix< T > &matrix, size_t precision, const std::filesystem::path &path, char separator=',') |
Writes a floating-point matrix with specified precision to a text file. | |
static txeo::MatrixIO | one_hot_encode_text_file (const std::filesystem::path &source_path, char separator, bool has_header, const std::filesystem::path &target_path, txeo::Logger &logger=txeo::LoggerConsole::instance()) |
Performs one-hot encoding in all non-numeric columns in a text file and writes the result to a target file. | |
A class to read file data to matrix and to write file data to a matrix.
Definition at line 24 of file MatrixIO.h.
|
inlineexplicit |
Constructs MatrixIO object.
path | Path to the file |
separator | Character delimiting each element in a row |
Definition at line 32 of file MatrixIO.h.
|
static |
Performs one-hot encoding in all non-numeric columns in a text file and writes the result to a target file.
source_path | The path to the source text file containing the input data. |
separator | The delimiter used in the input file (e.g., ',' for CSV). |
has_header | A flag indicating whether the input file has a header row. |
target_path | The path to the target text file where the encoded data will be written. |
MatrixIO
object representing the encoded data file pointing to target_path.txeo::MatrixIOError | If the source and target paths are the same, if the file cannot be opened, or if the input data is inconsistent (e.g., different types in the same column). |
Example Usage:
|
inline |
Definition at line 36 of file MatrixIO.h.
txeo::Matrix< T > txeo::MatrixIO::read_text_file | ( | bool | has_header = false | ) | const |
Returns a matrix with elements read from a text file.
T | Data type of the matrix elements |
has_header | Whether the first line contains column headers |
MatrixIOError |
|
inlinestatic |
Returns a matrix with elements read from a text file.
T | Data type of matrix elements |
path | File path to read from |
separator | Column separator character |
has_header | Whether to skip first line as header |
Definition at line 115 of file MatrixIO.h.
|
inline |
Definition at line 38 of file MatrixIO.h.
void txeo::MatrixIO::write_text_file | ( | const txeo::Matrix< T > & | matrix | ) | const |
Writes a matrix to a text file.
T | Data type of the matrix elements |
matrix | Matrix to write to file |
MatrixIOError |
void txeo::MatrixIO::write_text_file | ( | const txeo::Matrix< T > & | matrix, |
size_t | precision | ||
) | const |
Writes a floating-point matrix with specified precision to a text file.
T | Floating-point type (float/double) |
matrix | Matrix to write |
precision | Number of decimal places to write |
MatrixIOError |
|
inlinestatic |
Writes a matrix to a text file.
T | Data type of matrix elements |
matrix | Matrix to write |
path | Output file path |
separator | Column separator |
Definition at line 137 of file MatrixIO.h.
|
inlinestatic |
Writes a floating-point matrix with specified precision to a text file.
T | Floating-point type (float/double) |
matrix | Matrix to write |
precision | Decimal places to display |
path | Output file path |
separator | Column delimiter |
Definition at line 161 of file MatrixIO.h.