예제 #1
0
//------------------------------------------------------------------------------
void test_getLU()
{
   // Test "getLU"
   std::cout << "=============================================" << std::endl;
   std::cout << "Test getLU" << std::endl;

   Matrix* pA = new Matrix(ROWS,COLS,pArr,SIZE);

   // Show the base matrix 
   std::cout << "=============================================" << std::endl;
   std::cout << "A = " << std::endl;
   pA->showMatrix(); std::cout << std::endl;

   Matrix* pL = new Matrix(ROWS,COLS);
   Matrix* pU = new Matrix(ROWS,COLS);
   bool b1 = pA->getLU(pL, pU);
   std::cout << "getLU function return value = " << std::boolalpha << b1 << std::endl;
   std::cout << std::endl;

   std::cout << "L = " << std::endl;
   pL->showMatrix(); std::cout << std::endl;

   CVector* pV = getDiag(*pL); 
   std::cout << "Diagonal = all 1's (?)" << std::endl;
   pV->showVector(); std::cout << std::endl;

   std::cout << "U = " << std::endl;
   pU->showMatrix(); std::cout << std::endl;

   Matrix* pB = multiply(*pL, *pU);
   std::cout << "L*U = A (?)" << std::endl;
   pB->showMatrix(); std::cout << std::endl;

   // cleanup
   if (pA != 0) pA->unref();                     // Decrement the reference counter for pointer pA
   if (pB != 0) pB->unref();                     // Decrement the reference counter for pointer pB
   if (pL != 0) pL->unref();                     // Decrement the reference counter for pointer pL
   if (pU != 0) pU->unref();                     // Decrement the reference counter for pointer pU
   if (pV != 0) pV->unref();                     // Decrement the reference counter for pointer pV
}
예제 #2
0
SEXP Dtrmm(SEXP ENV, SEXP A, SEXP B, SEXP ALPHA, SEXP SIDE, SEXP TRANSA, SEXP UPLO, SEXP DIAG)
{
  cl_env *env = get_env(ENV);
  MATRIXCHECK(A, REALSXP);
  MATRIXCHECK(B, REALSXP);
  SCALARCHECK(ALPHA, REALSXP);
  clblasSide side = getSide(SIDE);
  clblasTranspose transA = getTrans(TRANSA);
  clblasUplo uplo = getUplo(UPLO);
  clblasDiag diag = getDiag(DIAG);
  double alpha = SCALARREAL(ALPHA);
  int ar = nrows(A), ac = ncols(A), br = nrows(B), bc = ncols(B);

  int size_a = LENGTH(A) * sizeof(double);
  int size_b = LENGTH(B) * sizeof(double);
  double *ap = REAL(A), *bp = REAL(B);
  cl_int err = Dtrmm_internal(
    env, ap, bp, alpha, side, transA, uplo, diag, ar, ac, br, bc, size_a, size_b);
  CHECK(err);

  return B;
}
예제 #3
0
//------------------------------------------------------------------------------
void test_getQR()
{
   // Test "getQR"
   std::cout << "=============================================" << std::endl;
   std::cout << "Test getQR" << std::endl;

   Matrix* pA = new Matrix(ROWS,COLS,pArr,SIZE);

   // Show the base matrix 
   std::cout << "=============================================" << std::endl;
   std::cout << "A = " << std::endl;
   pA->showMatrix(); std::cout << std::endl;

   Matrix* pQ = new Matrix(ROWS,COLS);
   Matrix* pR = new Matrix(ROWS,COLS);
   bool b1 = pA->getQR(pQ, pR);
   std::cout << "getQR function return value = " << std::boolalpha << b1 << std::endl;
   std::cout << std::endl;

   std::cout << "Q = " << std::endl;
   pQ->showMatrix(); std::cout << std::endl;

   std::cout << "R = " << std::endl;
   pR->showMatrix(); std::cout << std::endl;

   std::cout << "R = upper triangular (?)" << std::endl;
   std::cout << "Q = orthogonal (?)" << std::endl;
   std::cout << "det(Q) = " << pQ->getDeterm() << std::endl;
   std::cout << std::endl;

   Matrix* pQT = pQ->getTranspose();
   std::cout << "transpose(Q) = Q' (?)" << std::endl;
   pQT->showMatrix(); std::cout << std::endl;

   Matrix* pQinv = pQ->getInvLU();
   std::cout << "inverse(Q) = Q' (?)" << std::endl;
   pQinv->showMatrix(); std::cout << std::endl;

   Matrix* pI = multiply(*pQ, *pQinv); 
   std::cout << "Q * Qinv = I (?)" << std::endl;
   pI->showMatrix(); std::cout << std::endl;

   // get eigenvalues
   Matrix* pB = new Matrix(*pA);
   for (int i=0; i<10; i++)
   {
      pB->getQR(pQ, pR);
      pB = multiply(*pR, *pQ);
   }
   std::cout << "R * Q (after 10 iterations) = " << std::endl;
   pB->showMatrix(); std::cout << std::endl;
   CVector* pV = getDiag(*pB); 
   std::cout << "Diagonal = eigenvalue estimates" << std::endl;
   pV->showVector(); std::cout << std::endl;

   // cleanup
   if (pQ != 0) pQ->unref();                      // Decrement the reference counter for pointer pQ
   if (pR != 0) pR->unref();                      // Decrement the reference counter for pointer pR
   if (pQT != 0) pQT->unref();                    // Decrement the reference counter for pointer pQT
   if (pQinv != 0) pQinv->unref();                // Decrement the reference counter for pointer pQinv
   if (pI != 0) pI->unref();                      // Decrement the reference counter for pointer pI
}
예제 #4
0
파일: ndbsql.cpp 프로젝트: A-eolus/mysql
int print_err(SQLSMALLINT handletype, SQLHDBC hdbc) {
  getDiag(handletype, hdbc, 1, 1);

  return -1;
}
예제 #5
0
파일: vision.cpp 프로젝트: eandoe/kerl
/**
 * This is some of the big money.  This method will dynamically allocate masks
 * for circles rendered in grid.
 *
 * @param radius - The radius of the raster circle to be generated and added.
 */
vision::rastercircle vision::initRMask(int radius) {
	vision::rastercircle t;
	std::vector<coord> temp;
	int size = 4;
//BEGIN Midpoint circle algorithm.
	int f = 1 - radius;
	int ddF_x = 1;
	int ddF_y = -2 * radius;
	int x = 0;
	int y = radius;
	//calculated the number of points recursively
	while(x < y) {
		// ddF_x == 2 * x + 1;
		// ddF_y == -2 * y;
		// f == x*x + y*y - radius*radius + 2*x - y + 1;
		if(f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x;
		if(x != y) {
			size += 8;
		}
		else {
			size += 4;
		}
	}
//END Midpoint circle algorithm.

	//Create the array of coordinates
	for (int i = 0; i < size+4; ++i) {
		vision::coord tempc;
		tempc.x = 0.0;
		tempc.y = 0.0;
		tempc.z = 0.0;
		temp.push_back(tempc);
	}
//BEGIN Midpoint circle algorithm.
	f = 1 - radius;
	ddF_x = 1;
	ddF_y = -2 * radius;
	x = 0;
	y = radius;

	temp[0].x 			= radius; 	temp[0].y 			= 0; 		// 0
	temp[size/4].x 		= 0; 		temp[size/4].y 		= -radius; 	// Pi/2
	temp[size/2].x 		= -radius; 	temp[size/2].y 		= 0; 		// Pi
	temp[3*size/4].x 	= 0;		temp[3*size/4].y 	= radius; 	// 3Pi/2

	int it1 = 1;
	int it2 = size/4-1;
	int it3 = size/4+1;
	int it4 = size/2-1;
	int it5 = size/2+1;
	int it6 = 3*size/4-1;
	int it7 = 3*size/4+1;
	int it8 = size-1;
	while(x < y)
	{
		// ddF_x == 2 * x + 1;
		// ddF_y == -2 * y;
		// f == x*x + y*y - radius*radius + 2*x - y + 1;
		if(f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x;
		// 0 to 45
		temp[it1].x 	= y; 	temp[it1].y 	= -x;
		// 90 to 45
		temp[it2].x 	= x; 	temp[it2].y 	= -y;
		// 90 to 135
		temp[it3].x 	= -x; 	temp[it3].y 	= -y;
		// 180 to 135
		temp[it4].x 	= -y; 	temp[it4].y 	= -x;
		// 180 to 225
		temp[it5].x 	= -y;	temp[it5].y 	= x;
		// 270 to 225
		temp[it6].x 	= -x; 	temp[it6].y 	= y;
		// 270 to 315
		temp[it7].x 	= x; 	temp[it7].y 	= y;
		// 360 to 315
		temp[it8].x 	= y;	temp[it8].y 	= x;

		it1++; it3++; it5++; it7++;
		it2--; it4--; it6--; it8--;
	}
//END Midpoint circle algorithm.
	int max = ceil(sqrt(pow((double)radius, 2.0)/2.0));
	for(int i = 0; i < 4; i++) {
		temp[size+i].x = (i == 1 || i == 2) ? -max : max;
		temp[size+i].y = (i == 0 || i == 1) ? -max : max;
	}
	t.setMask(temp);

	display& disp = gamemanager::getDisplay();
	disp.printRaster(t);

	std::vector<std::vector<vision::coord> > lines;
	for(int i = 0; i < size; i++) {
		lines.push_back(computeLine(temp[i].x, temp[i].y));
		disp.printLine(temp[i].x, temp[i].y, lines[i]);
	}
	for(int i = 1; i <= 4; i++) {
		lines.push_back(getDiag(i, radius));
		disp.printLine(temp[size+i-1].x, temp[size+i-1].y, lines[size+i-1]);
	}

	t.setLines(lines);
	radiusmask.insert(std::make_pair(radius, t));
	return t;
}