Commit 019d55fe authored by Martin Beseda's avatar Martin Beseda

ENH: Simplified serialization implementaion for DataSet

parent 848f03a2
......@@ -2,11 +2,6 @@
// Created by martin on 7/13/18.
//
#include <iostream>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include "DataSet.h"
InvalidDimension::InvalidDimension() : std::runtime_error("Invalid dimension specified!") {};
......
//
// Created by martin on 7/13/18.
//
//TODO generovani dat
#ifndef INC_4NEURO_DATASET_H
#define INC_4NEURO_DATASET_H
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
#include <boost/serialization/base_object.hpp>
#include <boost/range/size_type.hpp>
#include <exception>
#include <string>
#include <functional>
#include <boost/serialization/base_object.hpp>
#include <boost/range/size_type.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
/**
* Class representing an error caused by an incorrect
......@@ -74,69 +80,10 @@ protected:
*/
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
if(Archive::is_loading::value) {
/* LOADING data */
ar & this->n_elements;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_tmp;
double tmp;
/* INPUT dimension */
size_t input_dim;
ar & input_dim;
/* OUTPUT dimension */
size_t output_dim;
ar & output_dim;
for(unsigned int i=0; i < this->n_elements; i++) {
/* INPUT vector */
std::vector<double> inputs;
for(unsigned int j=0; j < input_dim; j++) {
ar & tmp;
inputs.push_back(tmp);
}
/* OUTPUT vector */
//TODO check vector dimension like in input
std::vector<double> outputs;
for(unsigned int j=0; j < output_dim; j++) {
ar & tmp;
outputs.push_back(tmp);
}
/* Append to the data vector */
data_tmp.emplace_back(std::make_pair(inputs, outputs));
}
this->data = data_tmp;
} else {
/* STORING data */
//TODO check stored vectors dimensions
ar & this->n_elements;
size_t dim_inp, dim_out;
/* INPUT dimension */
dim_inp = std::get<0>(this->data[0]).size();
ar & dim_inp;
/* OUTPUT dimension */
dim_out = std::get<1>(this->data[0]).size();
ar & dim_out;
for(const auto p : this->data) {
/* Input vector */
for(auto val : std::get<0>(p)) {
ar & val;
}
/* Output vector */
for(auto val : std::get<1>(p)) {
ar & val;
}
}
}
ar & this->n_elements;
ar & this->input_dim;
ar & this->output_dim;
ar & this->data;
};
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment