aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-07 21:14:09 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-07 21:14:09 +0800
commitc866739c9464ec6638eac839e7a72ff2b1447377 (patch)
treeb2e8a156cb621bcf5ade50942db3ca0343e9d0b4
parente5d8fe50719f61138a21a568da9b06532a42dd5b (diff)
downloadopt-utilities-c866739c9464ec6638eac839e7a72ff2b1447377.tar.bz2
Set default error value to be 0 (original: 1)
Also some style fixes
-rw-r--r--misc/data_loaders.hpp119
1 files changed, 55 insertions, 64 deletions
diff --git a/misc/data_loaders.hpp b/misc/data_loaders.hpp
index 7bbb757..2b4f869 100644
--- a/misc/data_loaders.hpp
+++ b/misc/data_loaders.hpp
@@ -6,7 +6,9 @@
#ifndef DATA_LOADERS_H
#define DATA_LOADERS_H
+
#define OPT_HEADER
+
#include <core/fitter.hpp>
#include <data_sets/default_data_set.hpp>
#include <iostream>
@@ -24,14 +26,11 @@ namespace opt_utilities
template <typename Ty,typename Tx>
class dl_x_xe_y_ye;
-
template <typename Ty,typename Tx>
std::istream& operator>>(std::istream& ifs,dl_x_xe_y_ye<Ty,Tx>& dl);
-
template <typename Ty,typename Tx>
class dl_x_xu_xl_y_yu_yl;
-
template <typename Ty,typename Tx>
std::istream& operator>> (std::istream& ifs,dl_x_xu_xl_y_yu_yl<Ty,Tx>& dl);
@@ -54,21 +53,21 @@ namespace opt_utilities
void load_from(std::istream& ifs)
{
for(;;)
- {
- Tx x;
- Tx x_err;
- Ty y;
- Ty y_err(1);
-
- ifs>>x>>y>>y_err;
-
- if(!ifs.good())
- {
- break;
- }
- data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
- ds.add_data(d);
- }
+ {
+ Tx x;
+ Tx x_err;
+ Ty y;
+ Ty y_err(0);
+
+ ifs>>x>>y>>y_err;
+
+ if(!ifs.good())
+ {
+ break;
+ }
+ data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
+ ds.add_data(d);
+ }
//return ifs;
}
@@ -76,13 +75,11 @@ namespace opt_utilities
{
std::ifstream ifs(name);
load_from(ifs);
-
}
//friend std::istream& operator>> <>(std::istream& ifs,dl_x_y_ye<Ty,Tx>& dl);
};
-
/**
stream operator
*/
@@ -95,7 +92,7 @@ namespace opt_utilities
/**
- loading data from stream with file
+ loading data from stream with file
[x] [x error] [y] [y error]
*/
@@ -113,27 +110,27 @@ namespace opt_utilities
void load_from(std::istream& ifs)
{
for(;;)
- {
- Tx x;
- Tx x_err;
- Ty y;
- Ty y_err(1);
-
- ifs>>x>>x_err>>y>>y_err;
-
- if(!ifs.good())
- {
- break;
- }
- data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
- ds.add_data(d);
- }
+ {
+ Tx x;
+ Tx x_err;
+ Ty y;
+ Ty y_err(0);
+
+ ifs>>x>>x_err>>y>>y_err;
+
+ if(!ifs.good())
+ {
+ break;
+ }
+ data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
+ ds.add_data(d);
+ }
}
void load_from(const char* name)
{
std::ifstream ifs(name);
- load_from(ifs);
+ load_from(ifs);
}
};
@@ -150,7 +147,7 @@ namespace opt_utilities
/**
- loading data from stream with format
+ loading data from stream with format
[x] [x lower error] [x upper error] [y] [y lower error] [y upper error]
*/
@@ -158,37 +155,35 @@ namespace opt_utilities
class dl_x_xu_xl_y_yu_yl
{
private:
-
default_data_set<Ty,Tx> ds;
public:
data_set<Ty,Tx>& get_data_set()
{
return ds;
}
-
void load_from(std::istream& ifs)
{
for(;;)
- {
- Tx x;
- Tx xl,xu;
- Ty y;
- Ty yl(1),yu(1);
-
- ifs>>x>>xu>>xl>>y>>yu>>yl;
-
- xu=std::abs(xu);
- xl=std::abs(xl);
- yu=std::abs(yu);
- yl=std::abs(yl);
-
- if(!ifs.good())
- {
- break;
- }
- data<Ty,Tx> d(x,y,yl,yu,xl,xu);
- ds.add_data(d);
- }
+ {
+ Tx x;
+ Tx xl,xu;
+ Ty y;
+ Ty yl(0),yu(0);
+
+ ifs>>x>>xu>>xl>>y>>yu>>yl;
+
+ xu=std::abs(xu);
+ xl=std::abs(xl);
+ yu=std::abs(yu);
+ yl=std::abs(yl);
+
+ if(!ifs.good())
+ {
+ break;
+ }
+ data<Ty,Tx> d(x,y,yl,yu,xl,xu);
+ ds.add_data(d);
+ }
}
void load_from(const char* name)
@@ -208,11 +203,7 @@ namespace opt_utilities
dl.load_from(ifs);
return ifs;
}
-
-
-
}
-
#endif
//EOF