Changeset 2333
- Timestamp:
- Oct 15, 2010, 2:44:23 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/histogram_test.cc
r2202 r2333 29 29 #include <iostream> 30 30 31 using namespace theplu::yat::statistics; 32 using namespace theplu::yat; 33 34 void test_stream_constructor(test::Suite&); 35 31 36 int main(int argc, char* argv[]) 32 37 { 33 using namespace theplu::yat::statistics;34 using namespace theplu::yat;35 38 theplu::yat::test::Suite suite(argc, argv); 36 39 suite.err() << "testing histogram" << std::endl; … … 58 61 boost::forward_iterator_archetype<DataWeight>()); 59 62 } 63 test_stream_constructor(suite); 60 64 61 65 return suite.return_value(); 62 66 } 67 68 void test_stream_constructor(test::Suite& suite) 69 { 70 Histogram hist(0, 10, 10); 71 hist.add(3,2); 72 hist.add(1,3.14); 73 hist.add(20); 74 std::ostringstream oss; 75 oss << hist; 76 std::istringstream iss(oss.str()); 77 Histogram hist2(iss); 78 std::ostringstream oss2; 79 oss2 << hist2; 80 if (oss.str() != oss2.str()) { 81 suite.add(false); 82 suite.err() << "output:\n" << oss.str() 83 << "not equal to\n" << oss2.str(); 84 85 } 86 } -
trunk/yat/statistics/Histogram.cc
r2119 r2333 26 26 #include "Histogram.h" 27 27 28 #include <yat/utility/utility.h> 29 28 30 #include <algorithm> 29 31 #include <cassert> 30 32 #include <cmath> 31 33 #include <functional> 34 #include <istream> 32 35 #include <ostream> 33 36 … … 40 43 : xmax_(0), xmin_(0), sum_all_(), sum_histogram_() 41 44 { 45 } 46 47 48 Histogram::Histogram(std::istream& is) 49 { 50 std::string line; 51 getline(is, line, ':'); 52 getline(is, line, '\n'); 53 xmin_ = utility::convert<double>(line); 54 getline(is, line, ':'); 55 getline(is, line, '\n'); 56 xmax_ = utility::convert<double>(line); 57 getline(is, line, ':'); 58 getline(is, line, '\n'); 59 size_t n = utility::convert<size_t>(line); 60 histogram_.resize(n); 61 getline(is, line, '\n'); 62 getline(is, line, ':'); 63 getline(is, line, '\n'); 64 double total = utility::convert<double>(line); 65 getline(is, line, '\n'); 66 getline(is, line, '\n'); 67 std::vector<std::vector<double> > data; 68 utility::load(is, data); 69 for (size_t i=0; i<histogram_.size(); ++i) { 70 assert(data[i].size()==2); 71 add(data[i][0], data[i][1]); 72 } 73 add(xmax_, total - averager_all().sum_w()); 42 74 } 43 75 -
trunk/yat/statistics/Histogram.h
r2263 r2333 33 33 #include <boost/concept_check.hpp> 34 34 35 #include <iosfwd> 35 36 #include <string> 36 37 #include <vector> … … 57 58 /// 58 59 Histogram(void); 60 61 /** 62 \brief The istream constructor. 63 64 This constructor creates a Histogram from output (possibly) 65 created with operator<<. Note that the output from operator<< 66 does not contain all information required to restore the 67 Histogram. The values of all bins are restored, but the 68 averagers, averager_all(void) and averager_histogram(void), and 69 more specifically the second moment (sum_xx) in the averagers 70 cannot be restored due to lack of information in the output. 71 72 \since New in yat 0.7 73 */ 74 Histogram(std::istream&); 59 75 60 76 ///
Note: See TracChangeset
for help on using the changeset viewer.