25 using Row = std::array<double, N>;
43 inline const auto &
data()
const {
return _data; }
49 inline auto &
data() {
return _data; }
61 inline const Row &
first()
const {
return *_data.begin(); }
67 inline Row &
last() {
return *(_data.end() - 1); }
73 inline const Row &
last()
const {
return *(_data.end() - 1); }
80 inline const auto &
row(
size_t idx)
const {
90 inline auto &
row(
size_t idx) {
99 inline size_t rows()
const {
return _data.size(); }
111 inline void add(
const Row &lst) { _data.push_back(lst); }
118 inline void add(std::initializer_list<double> lst) {
119 Check::error_if<std::out_of_range>(
nmx_msgx(__func__),
124 std::copy(std::begin(lst), std::end(lst), std::begin(crow));
150 throw std::out_of_range(
nmx_msgx(__func__));
161 for (
const auto &
row : _data) {
175 for (
const auto &
row : _data) {
188 for (
size_t idx = 0; idx < _data.size(); idx++) {
189 clmn[idx] = _data[idx][cidx];
203 for (
size_t jdx = 0; jdx < clmn.size(); jdx++) {
205 crow[idx] = clmn[jdx];
206 _data.push_back(crow);
209 if (clmn.size() !=
rows()) {
212 throw std::range_error(
nmx_msgx(__func__));
214 for (
size_t jdx = 0; jdx <
rows(); jdx++) {
215 _data[jdx][idx] = clmn[jdx];
227 for (
auto &
row : _data) {
240 while (getline(ifs, line)) {
241 std::stringstream stream(line);
245 std::array<double, N> buffer;
246 while (getline(stream, token,
',')) {
247 buffer[idx] = std::strtod(token.c_str(), &ptr);
267 template<
class PREDICATE>
268 auto view(PREDICATE fn,
bool f =
true,
bool l =
true)
const {
271 view.add(static_cast<size_t>(0));
273 for (
size_t idx = 0; idx <
rows(); idx++) {
274 if (fn(_data[idx])) {
279 view.add(_data.size() - 1);
292 inline auto view(std::initializer_list<typename Container::iterator> lst,
298 view.add(static_cast<size_t>(0));
300 for (
const auto &itr : lst) {
302 const auto cidx = std::distance(_data.begin(), itr);
304 view.add(static_cast<size_t>(cidx));
307 view.add(_data.size() - 1);
322 for (
size_t idx = startidx; idx < _data.size(); idx += step) {
328 view.add(_data.size() - 1);
340 const size_t stepSize = std::ceil((
rows()) / (n - 1));
353 for (
const auto &
row : _data) {
355 clmn.push_back(
row[cidx]);
auto & operator+=(const Row &lst)
operator += Hinzufügen einer Reihe
void apply(FN fn)
apply ändere alle oder bestimmte Elemente
auto select_rows(size_t step, size_t startidx=0, bool last=false) const
view Teile der Tabelle als View
auto & operator+=(std::initializer_list< double > lst)
operator += Hinzufügen einer Reihe
std::vector< double > Column
auto view() const
view die ganze Tabelle als view
const Row & first() const
first erste Zeile (lesender Zugriff)
const auto & row(size_t idx) const
row Zugriff auf Zeile per Index (lesen)
void save(std::ostream &ofs, Format fmt) const
save Schreibe Tabelle in Datei
std::vector< Row > Container
static void error_if(const std::string &s, bool arg)
error_if Fehler wenn Bedingung erfüllt ist
Column column(size_t cidx, const FN &fn)
column erstelle Kopie einer Spalte
The Data class Eine Klasse für Zahlentabellen mit fester Anzahl von Spalten. Die Anzahl der Reihen wä...
auto column(size_t cidx) const
column Kopie einer Spalte
auto & data()
data schreibender Zugriff auf die interne Struktur
const Row & last() const
last letzte Zeile (lesender Zugriff)
void add(const Row &lst)
add füge eine neue Zeile hinzu
auto view(std::initializer_list< typename Container::iterator > lst, bool f=true, bool l=true)
view Teile der Tabelle als View
const auto & data() const
data lesender Zugriff auf die interne Struktur
auto view(PREDICATE fn, bool f=true, bool l=true) const
view Teile der Tabelle als View
void set_column(const Column clmn, size_t idx)
set_column Die Werte einer Spalte werden eingefügt oder ersetzt. Wenn die Tabelle leer ist wird erst ...
auto select_total_rows(size_t n, size_t start=0, bool l=true) const
get_total_rows generiere View mit eine Instanz vom Typ View bestimmter Anzahl von Spalten ...
void read_csv(std::ifstream &ifs)
read_csv lese Daten aus csv-Datei
Row & first()
first erste Zeile (schreibender Zugriff)
Row & last()
last letzte Zeile (schreibender Zugriff)
Data()
Data Standardkonstruktor die Tabelle enthält keine Daten.
void save(std::ostream &ofs, Format fmt, FN fn) const
save Schreibe Tabelle in Datei
void add(std::initializer_list< double > lst)
add füge eine neue Reihe hinzu. Die Anzahl der Elemente darf kleiner als die Anzahl der Spalten sein ...
auto & row(size_t idx)
row Zugriff auf Zeile per Index (schreiben)
double f(double x, void *params)
f
size_t columns() const
columns
std::array< double, N > Row