From 037cb0951b26442421ed39c193f68eea5fcefcab Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Fri, 21 Mar 2014 01:13:57 -0400 Subject: [PATCH] Built-in rand was causing severe perf issues. --- Base/include/MatrixSquare.h | 12 +++++------- Base/test/TestMatrix.cpp | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Base/include/MatrixSquare.h b/Base/include/MatrixSquare.h index 99edeca..6e76b40 100644 --- a/Base/include/MatrixSquare.h +++ b/Base/include/MatrixSquare.h @@ -50,16 +50,14 @@ namespace FasTC { // Returns them in eigVec and eigVal after kMaxNumIterations int PowerMethod(VectorBase &eigVec, T *eigVal = NULL, - const int kMaxNumIterations = 200, - const unsigned int kSeed = time(NULL)) { + const int kMaxNumIterations = 5) { - srand(kSeed); int numIterations = 0; VectorBase b; + T norm = 1.0/sqrt(static_cast(N)); for(int i = 0; i < N; i++) - b[i] = static_cast(rand()); - b.Normalize(); + b[i] = norm; bool badEigenValue = false; bool fixed = false; @@ -82,8 +80,8 @@ namespace FasTC { } VectorBase b; - for(int i = 0; i < N; i++) - b[i] = static_cast(rand()); + for(int i = 0; i < (N>>1); i++) + b[i] = 1; b.Normalize(); badEigenValue = true; diff --git a/Base/test/TestMatrix.cpp b/Base/test/TestMatrix.cpp index 089c3a0..dbd51c9 100644 --- a/Base/test/TestMatrix.cpp +++ b/Base/test/TestMatrix.cpp @@ -252,7 +252,7 @@ TEST(MatrixSquare, PowerMethod) { double e; FasTC::VectorBase x; - A.PowerMethod(x, &e, 20, 200); + A.PowerMethod(x, &e, 20); EXPECT_NEAR(x[0], 0.83205f, 0.0002); EXPECT_NEAR(x[1], 0.5547f, 0.0002);