Beispiel #1
0
	void ThreadBoost::SleepFor(millis_t millis, bool ensureSleepForCorrectTime)
	{
		
		if(ensureSleepForCorrectTime){
			StopWatch sw;
			millis_t remain = millis;
			do{
				boost::this_thread::sleep(boost::posix_time::milliseconds(remain));
				millis_t remain = millis - sw.Elapsed(false);
				if(remain <= 0) break;
				boost::this_thread::yield();
			}while(true);
		}else{
			boost::this_thread::sleep(boost::posix_time::milliseconds(millis));
		}

	}
Beispiel #2
0
bool Test(int n, int ix)
{
	// Test of the updating Cholesky factorization of the random SPD test matrix after the symmetric column/row deletion
	// Get a Test matrix
	SetPrintParams(2, 0);
	cout << endl << n << " x " << n << " Test matrix" << endl;
	cout << "Deleting row/column: " << ix << endl;

	SetPrintParams(7, 3);

	SpdMatrixT orig(n * (n + 1) / 2);
	SpdMatrixT reduced(n * (n + 1) / 2);

	StopWatch sw;
	if ( GetRandomMatrix(n, ix - 1, orig, reduced) != Status::Success )
	{
		cout << "Cannot get a test matrix, incorrect input parameter (matrix dimension)." << endl;
		return false;
	}
	cout <<"Time of the matrices generating = "  << sw.Elapsed() << " (s)\n";

	SpdCholT cholReduced(std::move(reduced), n - 1); 
	sw.Restart();
	Status rc = cholReduced.Factorize();
	cout <<"Time of the matrix factorizing = "  << sw.Elapsed() << " (s)\n";
	if ( rc != Status::Success )
	{
		cout << "Cannot factorize the Reduced test matrix, it is not positive-definite one. rc = " << rc << endl;
		return false;
	}
	cout << "The Reduced test matrix is factorized, rc = " << rc << endl; 

	SpdCholT cholOrig(std::move(orig), n); 
	rc = cholOrig.Factorize();
	if ( rc != Status::Success )
	{
		cout << "Cannot factorize the original test matrix, it is not positive-definite one. rc = " << rc << endl;
		return false;
	}
	cout << "The Original test matrix is factorized, rc = " << rc << endl;

	// Get assessment of the test matrix condition number
	cout.unsetf(std::ios::fixed);
	SetPrintParams(7, 1, std::ios::scientific);
	cout << "The Original matrix reciprocal condition number = " << cholOrig.GetRCond() << endl;

	sw.Restart();
	rc = cholOrig.UpdateDel(ix - 1);
	cout <<"Time of the matrix factor recalculating = "  << sw.Elapsed() << " (s)\n";
	if ( rc != Status::Success )
	{
		cout << "Cannot calculate the updated Cholesky factor of the Test matrix. rc = " << rc << endl;
		return false;
	}
	cout << "The updated Cholesky factor of the Original matrix is calculated. rc = " << rc << endl;

    SpdMatrixT diff(cholOrig.GetMatrix());
	SpdMatrixT fac = cholReduced.GetMatrix();

	int n1 = n - 1;
	Size_T sz = n1 * (n1 + 1) / 2;
	for ( Size_T i = 0; i < sz; ++i ) 
	{
		diff[i] -= fac[i];
	}

	Helper1T hlp;
	auto rn = hlp.GetVectorNorm2(sz, diff);
	cout << "Norm of diference of the Orginal(recalculated) and Reduced factors = " << rn << endl;

	VectorT b1(n1, 1);
	rc = cholReduced.Solve(b1);

	VectorT b2(n1, 1);
	rc = cholOrig.Solve(b2);
	for ( Size_T i = 0; i < n1; ++i ) 
	{
		b1[i] -= b2[i];
	}
	rn = hlp.GetVectorNorm2(n1, b1);
	cout << "Norm of diference of the solutions = " << rn << endl;

	return true;
}