1#ifndef SINGLEPP_LOADERS_RANKINGS_HPP
2#define SINGLEPP_LOADERS_RANKINGS_HPP
4#include "byteme/PerByte.hpp"
5#include "byteme/RawFileReader.hpp"
6#include "byteme/GzipFileReader.hpp"
7#include "byteme/ZlibBufferReader.hpp"
34template<
typename Value_ =
double,
typename Index_ =
int,
typename Rank_ =
int>
58template<
typename Value_,
typename Index_>
62 std::vector<int> values;
65 bool non_empty =
false;
68 bool has_nfeatures =
false;
69 auto check_nfeatures = [&]() ->
void {
72 nfeatures = field + 1;
73 }
else if (field + 1 != nfeatures) {
74 throw std::runtime_error(
"number of fields on each line should be equal to the number of features");
78 std::unique_ptr<byteme::PerByteInterface<char> > pbptr;
80 pbptr.reset(
new byteme::PerByteParallel<char, byteme::Reader*>(&reader));
82 pbptr.reset(
new byteme::PerByteSerial<char, byteme::Reader*>(&reader));
86 bool okay = pb.valid();
94 throw std::runtime_error(
"fields should not be empty");
96 values.push_back(current);
102 }
else if (x ==
',') {
104 throw std::runtime_error(
"fields should not be empty");
106 values.push_back(current);
111 }
else if (std::isdigit(x)) {
114 current += (x -
'0');
117 throw std::runtime_error(
"fields should only contain integer ranks");
121 if (field || non_empty) {
124 throw std::runtime_error(
"fields should not be empty");
126 values.push_back(current);
153template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
155 byteme::RawFileReaderOptions read_opt;
157 byteme::RawFileReader reader(path, read_opt);
158 return internal::load_rankings<Value_, Index_>(reader, options.
parallel);
173template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
175 byteme::GzipFileReaderOptions read_opt;
177 byteme::GzipFileReader reader(path, read_opt);
178 return internal::load_rankings<Value_, Index_>(reader, options.
parallel);
194template<
typename Value_ = singlepp::DefaultValue,
typename Index_ = singlepp::DefaultIndex>
196 byteme::ZlibBufferReaderOptions read_opt;
199 byteme::ZlibBufferReader reader(buffer, len, read_opt);
200 return internal::load_rankings<Value_, Index_>(reader, options.
parallel);
Load pre-processed single reference datasets.
Definition labels.hpp:23
RankMatrix< Value_, Index_ > load_rankings_from_zlib_buffer(const unsigned char *buffer, size_t len, const LoadRankingsOptions &options)
Definition rankings.hpp:195
RankMatrix< Value_, Index_ > load_rankings_from_text_file(const char *path, const LoadRankingsOptions &options)
Definition rankings.hpp:154
RankMatrix< Value_, Index_ > load_rankings_from_gzip_file(const char *path, const LoadRankingsOptions &options)
Definition rankings.hpp:174
Options for loading rankings.
Definition rankings.hpp:40
bool parallel
Definition rankings.hpp:44
size_t buffer_size
Definition rankings.hpp:49