ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
IO.hpp
Go to the documentation of this file.
1
5#pragma once
6
8
9#include "utils/Invariant.hpp"
10
11#include <nlohmann/json.hpp>
12#include <string>
13
14namespace ppforest2::io {
15 using ErrorHandler = void (*)(bool, std::string const&);
16
21 void check_file_exists(std::string const& path);
22
27 void check_file_not_exists(std::string const& path);
28
33 void check_dir_not_exists(std::string const& path);
34}
35
42 std::string ensure_extension(std::string const& path);
43
52 nlohmann::json read_file(std::string const& path, ErrorHandler on_error = invariant);
53
62 void write_file(nlohmann::json const& data, std::string const& path, ErrorHandler on_error = invariant);
63}
64
72 void write_file(std::string const& content, std::string const& path, ErrorHandler on_error = invariant);
73}
74
88 stats::DataPacket read(std::string const& filename);
89
109 stats::DataPacket read_sorted(std::string const& filename);
110
116 void write(stats::DataPacket const& data, std::string const& filename);
117
126 struct FeatureSet {
129 std::vector<std::vector<std::string>> raw_rows;
130 };
131
144 FeatureSet read_features_from_string(std::string const& content);
145}
void invariant(bool condition, char const *message)
Runtime assertion that throws on failure.
Definition IO.hpp:75
FeatureSet read_features_from_string(std::string const &content)
Parse a feature-only CSV from an in-memory string.
void write(stats::DataPacket const &data, std::string const &filename)
Write a DataPacket to a CSV file (features followed by label, no header).
stats::DataPacket read_sorted(std::string const &filename)
Read a CSV file and sort rows ascending by the response column.
stats::DataPacket read(std::string const &filename)
Read a CSV file into a DataPacket.
Definition IO.hpp:36
nlohmann::json read_file(std::string const &path, ErrorHandler on_error=invariant)
Read a JSON file and parse its contents.
std::string ensure_extension(std::string const &path)
Ensure a file path ends with the ".json" extension.
void write_file(nlohmann::json const &data, std::string const &path, ErrorHandler on_error=invariant)
Write a JSON object to a file (pretty-printed with indent 2).
Definition IO.hpp:65
void write_file(std::string const &content, std::string const &path, ErrorHandler on_error=invariant)
Write a string to a file.
Definition Color.hpp:31
void check_file_exists(std::string const &path)
Exit with an error if a file does not exist at the given path.
void check_dir_not_exists(std::string const &path)
Exit with an error if a directory already exists at the given path.
void(*)(bool, std::string const &) ErrorHandler
Definition IO.hpp:15
void check_file_not_exists(std::string const &path)
Exit with an error if a file already exists at the given path.
std::vector< std::string > Names
Vector of name strings — used uniformly for class labels (group_names[i] is the label for GroupId == ...
Definition Types.hpp:49
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:33
Result of parsing a feature-only CSV (no response column).
Definition IO.hpp:126
std::vector< std::vector< std::string > > raw_rows
Definition IO.hpp:129
types::FeatureMatrix x
Definition IO.hpp:127
types::Names feature_names
Definition IO.hpp:128
Bundled dataset: features, response, and group labels.
Definition DataPacket.hpp:19