7 #ifndef JADE_REMA_HPP__
8 #define JADE_REMA_HPP__
10 #include "jade.args.hpp"
11 #include "jade.matrix.hpp"
20 template <
typename TChar>
25 typedef std::basic_istream<char_type>
istream;
26 typedef std::basic_ostream<char_type>
ostream;
35 , _seed (_read_seed(a))
36 , _num_markers (_read_num_markers(a))
51 size_t row_count, col_count;
52 if (!(in >> row_count >> col_count))
53 throw jade::error(
"error reading matrix dimensions");
59 const auto marker_count = std::min(col_count, _num_markers);
66 std::vector<bool> filter_flags;
67 filter_flags.resize(col_count,
true);
69 typedef std::vector<size_t> vector_type;
70 vector_type indices (col_count);
71 std::iota(indices.begin(), indices.end(), 0);
73 std::shuffle(indices.begin(), indices.end(), _engine);
74 indices.resize(marker_count);
75 for (
const auto index : indices)
76 filter_flags[index] =
false;
82 _filter(in, out, row_count, col_count, marker_count, filter_flags);
91 if (!(in >> r) && in.eof())
94 throw jade::error(
"error reading second matrix dimensions");
95 if (r != row_count || c != col_count)
96 throw jade::error(
"inconsistent second matrix dimensions");
99 _filter(in, out, row_count, col_count, marker_count, filter_flags);
105 throw jade::error(
"error reading third matrix dimensions");
106 if (r != row_count || c != col_count)
107 throw jade::error(
"inconsistent third matrix dimensions");
110 _filter(in, out, row_count, col_count, marker_count, filter_flags);
117 const auto ch = in.get();
120 if (!std::isspace(ch))
121 throw jade::error(
"unexpected symbol after matrix data");
129 typedef std::default_random_engine engine_type;
134 typedef engine_type::result_type seed_type;
140 const size_t row_count,
141 const size_t col_count,
142 const size_t marker_count,
143 const std::vector<bool> & filter_flags)
151 for (
size_t r = 0; r < row_count; r++)
154 for (
size_t c = 0; c < col_count; c++)
156 const auto is_unfiltered = !filter_flags[c];
163 if ((ch = in.get()) < 0)
164 throw jade::error(
"unexpected end of matrix data");
165 while (std::isspace(ch));
176 while ((ch = in.get()) >= 0 && !std::isspace(ch));
183 out << (++m == _num_markers
194 static size_t _read_num_markers(
197 auto n = a.
pop<
size_t>();
199 throw error(
"invalid number of markers");
207 static seed_type _read_seed(
210 return a.
read(
"--seed",
"-s", std::random_device()());
218 typedef basic_rema<char> rema;
221 #endif // JADE_REMA_HPP__