12 if(std::isprint(c) != 0) {
16 result.push_back(
'\\');
23 if(data.size() == 0) {
28 for(
int i = 0; i < data.size() - 1; ++i) {
29 stream << data.coeff(i) <<
' ';
32 stream << data.coeff(data.size() - 1);
38 for (
int j = 0; j < data.size(); ++j) {
39 stream >> data.coeffRef(j);
43 THROW_ERROR(
"Error while reading a {} element dense vector from text data", data.size());
61 THROW_ERROR(
"Invalid number of rows {} specified in header '{}'", NumRows, content);
64 THROW_ERROR(
"Invalid number of rows {} specified in header '{}'", NumCols, content);
70 THROW_ERROR(
"Found additional text '{}' in header '{}'", rest, content);
73 return {NumRows, NumCols};
78 std::string line_buffer;
79 std::getline(source, line_buffer);
82 std::vector<std::vector<long>> label_data;
83 label_data.resize(header.NumCols);
86 long num_rows = header.NumRows;
87 long num_cols = header.NumCols;
89 while (std::getline(source, line_buffer)) {
90 if (line_buffer.empty())
92 if (line_buffer.front() ==
'#')
95 if(example >= num_rows) {
96 THROW_ERROR(
"Encountered row {:5} but only expected {:5} rows.", example, num_rows);
101 long adjusted_index = index;
102 if (adjusted_index >= num_cols || adjusted_index < 0) {
103 THROW_ERROR(
"Encountered index {:5}. Number of columns "
104 "was specified as {}.", index, num_cols);
108 THROW_ERROR(
"Encountered value {} at index {}.", value, index);
110 label_data[adjusted_index].push_back(example);
112 }
catch (std::runtime_error& e) {
113 THROW_ERROR(
"Error reading example {}: {}.", example + 1, e.what());
117 return {num_rows, num_cols, std::move(label_data)};
building blocks for io procedures that are used by multiple io subsystems
std::string print_char(char c)
const char * to_string(WeightFormat format)
std::ostream & write_vector_as_text(std::ostream &stream, const Eigen::Ref< const DenseRealVector > &data)
Writes the given vector as space-separated human-readable numbers.
std::istream & read_vector_from_text(std::istream &stream, Eigen::Ref< DenseRealVector > data)
Reads the given vector as space-separated human-readable numbers.
MatrixHeader parse_header(const std::string &content)
LoLBinarySparse read_binary_matrix_as_lol(std::istream &source)
void parse_sparse_vector_from_text(const char *feature_part, F &&callback)
parses sparse features given in index:value text format.
Main namespace in which all types, classes, and functions are defined.
Binary Sparse Matrix in List-of-Lists format.