Built-in rand was causing severe perf issues.

This commit is contained in:
Pavel Krajcevski 2014-03-21 01:13:57 -04:00
parent 675ebc28a1
commit 037cb0951b
2 changed files with 6 additions and 8 deletions

View File

@ -50,16 +50,14 @@ namespace FasTC {
// Returns them in eigVec and eigVal after kMaxNumIterations // Returns them in eigVec and eigVal after kMaxNumIterations
int PowerMethod(VectorBase<T, N> &eigVec, int PowerMethod(VectorBase<T, N> &eigVec,
T *eigVal = NULL, T *eigVal = NULL,
const int kMaxNumIterations = 200, const int kMaxNumIterations = 5) {
const unsigned int kSeed = time(NULL)) {
srand(kSeed);
int numIterations = 0; int numIterations = 0;
VectorBase<T, N> b; VectorBase<T, N> b;
T norm = 1.0/sqrt(static_cast<T>(N));
for(int i = 0; i < N; i++) for(int i = 0; i < N; i++)
b[i] = static_cast<T>(rand()); b[i] = norm;
b.Normalize();
bool badEigenValue = false; bool badEigenValue = false;
bool fixed = false; bool fixed = false;
@ -82,8 +80,8 @@ namespace FasTC {
} }
VectorBase<T, N> b; VectorBase<T, N> b;
for(int i = 0; i < N; i++) for(int i = 0; i < (N>>1); i++)
b[i] = static_cast<T>(rand()); b[i] = 1;
b.Normalize(); b.Normalize();
badEigenValue = true; badEigenValue = true;

View File

@ -252,7 +252,7 @@ TEST(MatrixSquare, PowerMethod) {
double e; double e;
FasTC::VectorBase<double, 2> x; FasTC::VectorBase<double, 2> x;
A.PowerMethod(x, &e, 20, 200); A.PowerMethod(x, &e, 20);
EXPECT_NEAR(x[0], 0.83205f, 0.0002); EXPECT_NEAR(x[0], 0.83205f, 0.0002);
EXPECT_NEAR(x[1], 0.5547f, 0.0002); EXPECT_NEAR(x[1], 0.5547f, 0.0002);