Bläddra i källkod

win32: fixed drand48 usage

unknown 12 år sedan
förälder
incheckning
3c2a6b7434

+ 4 - 0
cbaselib/FeaturePool.cpp

@@ -37,7 +37,11 @@ Feature *FeaturePool::getRandomFeature() const
 	assert(size() == cumsum.size());
 	assert(! empty());
 	double sum = cumsum[ cumsum.size() - 1 ];
+#ifdef WIN32
+	double pos = (double( rand() ) / RAND_MAX )* sum;
+#else
 	double pos = drand48() * sum;
+#endif
 
 	vector<double>::const_iterator j = lower_bound(cumsum.begin(), cumsum.end(), pos);
 	uint index = distance(cumsum.begin(), j);

+ 1 - 0
classifier/fpclassifier/boosting/FPCFullSearch.cpp

@@ -6,6 +6,7 @@
 
 */
 #include <iostream>
+#include <time.h>
 
 #include "FPCFullSearch.h"
 #include "vislearning/features/fpfeatures/createFeatures.h"

+ 9 - 2
features/localfeatures/IDRandomSampling.cpp

@@ -59,7 +59,11 @@ int IDRandomSampling::getInterests(const NICE::Image & img,
 
 	for (size_t i = 0; i < (size_t) numSamples; i++)
 	{
+#ifdef WIN32
+		double sr = double( rand() ) / RAND_MAX;
+#else
 		double sr = drand48();
+#endif
 		int r = len - 1;
 		while ((p[r] > sr) && (r > 0))
 			r--;
@@ -72,10 +76,13 @@ int IDRandomSampling::getInterests(const NICE::Image & img,
 	{
 		double r = sizes[i];
 		double scale = (r + rmin) / 6.0;
-
+#ifdef WIN32
+		double x = double( rand() ) / RAND_MAX * (img.width() - 2 * r) + r;
+		double y = double( rand() ) / RAND_MAX * (img.height() - 2 * r) + r;
+#else
 		double x = drand48() * (img.width() - 2 * r) + r;
-
 		double y = drand48() * (img.height() - 2 * r) + r;
+#endif
 
 		Vector pos(3);
 		pos[0] = x;

+ 7 - 0
math/pdf/tests/TestPDF.cpp

@@ -25,6 +25,8 @@
 #include "core/vector/VVector.h"
 #include "vislearning/math/pdf/PDFGaussian.h"
 
+#include <time.h>
+
 using namespace std;
 using namespace NICE;
 using namespace OBJREC;
@@ -76,7 +78,12 @@ void TestPDF::TestPDFComputation()
   cerr << "Sample from Gaussian" << endl;
   //init random
   if ( init_random )
+#ifdef WIN32
+	srand ( time ( NULL ) );
+#else
     srand48 ( time ( NULL ) );
+#endif
+    
 
   // generate random symmetric matrix
   for ( uint i = 0 ; i < dim ; i++ )

+ 11 - 1
math/topics/PLSA.cpp

@@ -7,6 +7,7 @@
 */
 #include <iostream>
 #include <assert.h>
+#include <time.h>
 #include <core/vector/Algorithms.h>
 
 #include "PLSA.h"
@@ -23,7 +24,12 @@ PLSA::PLSA( int maxiterations,
 	    double betadecrease,
 	    double holdoutportion )
 {
-    srand48(time(NULL));
+#ifdef WIN32
+	srand ( time ( NULL ) );
+#else
+    srand48 ( time ( NULL ) );
+#endif
+
     
     this->maxiterations = maxiterations;
     this->delta_eps = delta_eps;
@@ -150,7 +156,11 @@ void PLSA::randomizeBuffer ( double *A, long size )
 {
     for ( int index = 0 ; index < size ; index++ )
     {
+#ifdef WIN32
+	A[index] = (double( rand() ) / RAND_MAX );
+#else
 	A[index] = drand48();
+#endif
     }
 }
 

+ 8 - 1
optimization/mapestimation/progs/testDirichlet.cpp

@@ -65,13 +65,20 @@ void simulation ( int samplesCount )
     // refactor-nice.pl: check this substitution
     // old: Vector alpha (dimension);
     NICE::Vector alpha (dimension);
-
+#ifdef WIN32
+	srand(time(NULL));
+#else
     srand48(time(NULL));
+#endif
 
     double s = 0.0;
     for ( int i = 0 ; i < dimension ; i++ )
     {
+#ifdef WIN32
+	alpha[i] = double( rand() ) / RAND_MAX * 3.0;
+#else
 	alpha[i] = drand48() * 3.0;
+#endif
 	s += alpha[i];
     }