mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Changing random.h to use cstdlib for Windows compability.
As discussed with Sameer today. Change-Id: If3d0284830c6591c71cc77b8400cafb45c0da61f
This commit is contained in:
@@ -273,27 +273,6 @@ void SetSolverOptionsFromFlags(BALProblem* bal_problem,
|
||||
SetOrdering(bal_problem, options);
|
||||
}
|
||||
|
||||
// Uniform random numbers between 0 and 1.
|
||||
double UniformRandom() {
|
||||
return static_cast<double>(random()) / static_cast<double>(RAND_MAX);
|
||||
}
|
||||
|
||||
// Normal random numbers using the Box-Mueller algorithm. Its a bit
|
||||
// wasteful, as it generates two but only returns one.
|
||||
double RandNormal() {
|
||||
double x1, x2, w, y1, y2;
|
||||
do {
|
||||
x1 = 2.0 * UniformRandom() - 1.0;
|
||||
x2 = 2.0 * UniformRandom() - 1.0;
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while ( w >= 1.0 );
|
||||
|
||||
w = sqrt((-2.0 * log(w)) / w);
|
||||
y1 = x1 * w;
|
||||
y2 = x2 * w;
|
||||
return y1;
|
||||
}
|
||||
|
||||
void BuildProblem(BALProblem* bal_problem, Problem* problem) {
|
||||
const int point_block_size = bal_problem->point_block_size();
|
||||
const int camera_block_size = bal_problem->camera_block_size();
|
||||
|
||||
@@ -34,19 +34,20 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include "ceres/internal/port.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
inline void SetRandomState(int state) {
|
||||
srandom(state);
|
||||
srand(state);
|
||||
}
|
||||
|
||||
inline int Uniform(int n) {
|
||||
return random() % n;
|
||||
return rand() % n;
|
||||
}
|
||||
|
||||
inline double RandDouble() {
|
||||
double r = static_cast<double>(random());
|
||||
double r = static_cast<double>(rand());
|
||||
return r / RAND_MAX;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user