diff --git a/include/hpp/statistics/bin.hh b/include/hpp/statistics/bin.hh index 0ea9e4a22f8f8c1bca4f30f1cc1ed379dd4f9fba..feb122d161c9644f1a6c6fe14e838d4631e9e35e 100644 --- a/include/hpp/statistics/bin.hh +++ b/include/hpp/statistics/bin.hh @@ -98,7 +98,7 @@ namespace hpp { /// Return the number of times a observation has recorded. It is the /// total number of observations. - unsigned int numberOfObservations () const + std::size_t numberOfObservations () const { return counts_; } @@ -141,7 +141,7 @@ namespace hpp { private: Container bins_; - unsigned int counts_; + std::size_t counts_; }; template < typename T > diff --git a/include/hpp/statistics/distribution.hh b/include/hpp/statistics/distribution.hh index 4ee285e1230bffc9ea98fbb8edcd7c1c00a7d573..e1d76f9f225e46460e1390fafdeb93b0613d7e39 100644 --- a/include/hpp/statistics/distribution.hh +++ b/include/hpp/statistics/distribution.hh @@ -30,7 +30,7 @@ namespace hpp { class DiscreteDistribution { public: - typedef unsigned int Weight_t; + typedef std::size_t Weight_t; typedef typename std::pair < Weight_t, Value_t> ProbaTPair; typedef typename std::vector < ProbaTPair >::iterator iterator; typedef typename std::vector < ProbaTPair >::const_iterator const_iterator; @@ -101,7 +101,7 @@ namespace hpp { std::vector < Proba_t > probabilities () const { if (values_.empty ()) return std::vector < Proba_t > (0); std::vector < Proba_t > proba (values_.size()); - Proba_t total = cumulative_weights_.back(); + Proba_t total = (double)cumulative_weights_.back(); for (size_t i = 0; i < values_.size (); i++) proba[i] = values_[i].first / total; return proba; diff --git a/include/hpp/statistics/success-bin.hh b/include/hpp/statistics/success-bin.hh index 292e1248cf4d7a32a4a87e5d9a16959636d2573f..ba930f427bbfac373f576bb879c1709029c6db72 100644 --- a/include/hpp/statistics/success-bin.hh +++ b/include/hpp/statistics/success-bin.hh @@ -73,10 +73,10 @@ namespace hpp { /// to define a new reason. class Reason { public: - unsigned int id; + std::size_t id; std::string what; private: - Reason (unsigned int a_id, std::string a_what) : + Reason (std::size_t a_id, std::string a_what) : id (a_id), what (a_what) {} friend Reason SuccessBin::createReason (const std::string&); }; @@ -88,7 +88,7 @@ namespace hpp { /// The reason for 'success'. const static Reason REASON_SUCCESS; - static unsigned int reasonID_last; + static std::size_t reasonID_last; std::ostream& printValue (std::ostream& os) const; }; @@ -112,13 +112,13 @@ namespace hpp { void addFailure (const SuccessBin::Reason& r = SuccessBin::REASON_UNKNOWN); /// Count the number of success. - unsigned int nbSuccess () const; + std::size_t nbSuccess () const; /// Count the number of failure, in total. - unsigned int nbFailure () const; + std::size_t nbFailure () const; /// Count the number of a particular failure. - unsigned int nbFailure (const SuccessBin::Reason& r) const; + std::size_t nbFailure (const SuccessBin::Reason& r) const; }; } // namespace statistics } // namespace hpp diff --git a/src/success-bin.cc b/src/success-bin.cc index dff220a8f7b08789e64287c5c2cb9b6bf8622297..c7df8b307a1e9cb88ab1b2001f17bd93f141cda8 100644 --- a/src/success-bin.cc +++ b/src/success-bin.cc @@ -20,7 +20,7 @@ namespace hpp { namespace statistics { - unsigned int SuccessBin::reasonID_last = 0; + std::size_t SuccessBin::reasonID_last = 0; const SuccessBin::Reason SuccessBin::REASON_SUCCESS = SuccessBin::createReason ("Success"); const SuccessBin::Reason SuccessBin::REASON_UNKNOWN = SuccessBin::createReason ("Unknown"); @@ -77,17 +77,17 @@ namespace hpp { insert (SuccessBin (true)); } - unsigned int SuccessStatistics::nbSuccess () const + std::size_t SuccessStatistics::nbSuccess () const { return freq (SuccessBin(true)); } - unsigned int SuccessStatistics::nbFailure () const + std::size_t SuccessStatistics::nbFailure () const { return numberOfObservations() - nbSuccess(); } - unsigned int SuccessStatistics::nbFailure (const SuccessBin::Reason& r) const + std::size_t SuccessStatistics::nbFailure (const SuccessBin::Reason& r) const { return freq (SuccessBin (false, r)); } diff --git a/tests/test-distribution.cc b/tests/test-distribution.cc index 6bf22b0ccf17db0ba37bd04a7bf5fb8d86e6b3d5..83222b14d910240a22d49fb3bc3ab41e4348c090 100644 --- a/tests/test-distribution.cc +++ b/tests/test-distribution.cc @@ -39,12 +39,12 @@ int test1 () std::vector < Proba_t > p = dd.probabilities (); for (size_t i = 0; i < p.size (); i++) - if (p[i] - (double)(weight[i] / (double)total_weight) > DBL_EPSILON - || - p[i] + (double)(weight[i] / (double)total_weight) > DBL_EPSILON) { + if (p[i] - ((double) weight[i] / (double)total_weight) > DBL_EPSILON + || - p[i] + ((double)weight[i] / (double)total_weight) > DBL_EPSILON) { std::cout << "p[" << i << "] = " << p[i] << std::endl << "weight[" << i << "] = " << weight[i] << std::endl << "Total weight = " << total_weight << std::endl - << "Difference = " << p[i] - (double)(weight[i] / (double)total_weight) << std::endl; + << "Difference = " << p[i] - ((double)weight[i] / (double)total_weight) << std::endl; return EXIT_FAILURE; } @@ -79,12 +79,12 @@ int test2 () std::vector < Proba_t > p = dd.probabilities (); for (size_t i = 0; i < p.size (); i++) - if (p[i] - (double)(weight[i] / (double)total_weight) > DBL_EPSILON - || - p[i] + (double)(weight[i] / (double)total_weight) > DBL_EPSILON) { + if (p[i] - ((double)weight[i] / (double)total_weight) > DBL_EPSILON + || - p[i] + ((double)weight[i] / (double)total_weight) > DBL_EPSILON) { std::cout << "p[" << i << "] = " << p[i] << std::endl << "weight[" << i << "] = " << weight[i] << std::endl << "Total weight = " << total_weight << std::endl - << "Difference = " << p[i] - (double)(weight[i] / (double)total_weight) << std::endl; + << "Difference = " << p[i] - ((double)weight[i] / (double)total_weight) << std::endl; return EXIT_FAILURE; } @@ -109,7 +109,7 @@ int test2 () int main () { /* initialize random seed: */ - srand (time(NULL)); + srand ((unsigned int)time(NULL)); std::cout.precision(15); diff --git a/tests/test-statistics.cc b/tests/test-statistics.cc index 786f839c926cee8fd4988ab9a97eed3ab3a21600..f039e6e3bb9fd2c3d4498c18617cb4214b80f988 100644 --- a/tests/test-statistics.cc +++ b/tests/test-statistics.cc @@ -60,7 +60,7 @@ class TestStatistics : public Statistics <TestBin> { int main () { - srand (time(NULL)); + srand ((unsigned int)time(NULL)); TestStatistics t; double *check = new double [100]; diff --git a/tests/test-successstatistics.cc b/tests/test-successstatistics.cc index 1f3826d177700cdc70b4e635f0e3aab9255bb22e..754eaa0bfc9cec10f60ed32030c410c6d9228c1a 100644 --- a/tests/test-successstatistics.cc +++ b/tests/test-successstatistics.cc @@ -27,14 +27,14 @@ using namespace hpp; int main () { /* initialize random seed: */ - srand (time(NULL)); + srand ((unsigned int)time(NULL)); using namespace hpp::statistics; SuccessStatistics ss; - unsigned int counter[3]; + std::size_t counter[3]; counter[0]=0; counter[1]=0; counter[2]=0; for (int i = 0; i < 100; i++) { - unsigned int nb = rand() % 3; + std::size_t nb = rand() % 3; counter[nb]++; switch (nb) { case 0: