void SpeciesInfo::augmentDensityGridGrad(const ScalarFieldArray& E_n, std::vector<vector3<> >* forces)
{	static StopWatch watch("augmentDensityGridGrad"); watch.start();
	augmentDensityGrid_COMMON_INIT
	if(!nAug) augmentDensityInit();
	const GridInfo &gInfo = e->gInfo;
	double dGinv = 1./gInfo.dGradial;
	matrix E_nAugRadial = zeroes(nCoeffHlf, e->eInfo.nDensities * atpos.size() * Nlm);
	double* E_nAugRadialData = (double*)E_nAugRadial.dataPref();
	matrix nAugRadial; const double* nAugRadialData=0;
	if(forces)
	{	matrix nAugTot = nAug; nAugTot.allReduce(MPIUtil::ReduceSum);
		nAugRadial = QradialMat * nAugTot;
		nAugRadialData = (const double*)nAugRadial.dataPref();
	}
	VectorFieldTilde E_atpos; if(forces) nullToZero(E_atpos, gInfo);
	for(unsigned s=0; s<E_n.size(); s++)
	{	ScalarFieldTilde ccE_n = Idag(E_n[s]);
		for(unsigned atom=0; atom<atpos.size(); atom++)
		{	int atomOffs = nCoeff * Nlm * (atom + atpos.size()*s);
			if(forces) initZero(E_atpos);
			callPref(nAugmentGrad)(Nlm, gInfo.S, gInfo.G, nCoeff, dGinv, forces? (nAugRadialData+atomOffs) :0, atpos[atom],
				ccE_n->dataPref(), E_nAugRadialData+atomOffs, forces ? E_atpos.dataPref() : vector3<complex*>(), nagIndex, nagIndexPtr);
			if(forces) for(int k=0; k<3; k++) (*forces)[atom][k] -= sum(E_atpos[k]);
		}
	}
	E_nAug = dagger(QradialMat) * E_nAugRadial;  //propagate from spline coeffs to radial functions
	E_nAug.allReduce(MPIUtil::ReduceSum);
	watch.stop();
}
Пример #2
0
int main (int argc, const char *argv[])
{

  if (argc < 1)
    {
      puts ("no input files");
      return 0;
    }

  FILE *fp = fopen (argv[1], "r");
  long pstack[50];
  long *pstackTop = pstack;
  char c = 0;
  char data[DATA_SIZE];
  initZero (data, DATA_SIZE);
  char *dp = data;
  while ((c = fgetc (fp)) != EOF)
    {
      switch (c)
	{
	case '>':		//increment pointer
	  ++dp;
	  break;
	case '<':		//decrement pointer
	  --dp;
	  break;
	case '+':		//increment data at pointer
	  ++*dp;
	  break;
	case '-':		//decrement data at pointer
	  --*dp;
	  break;
	case '[':		//continue if data at pointer, else jump to next ]
	  if (*dp)
	    {
	      ++pstackTop;
	      *pstackTop = ftell (fp) - 1;
	    }
	  else
	    {
	      while (fgetc (fp) != ']');
	    }
	  break;
	case ']':		//return to corresponding [
	  fseek (fp, *pstackTop, SEEK_SET);
	  --pstackTop;
	  break;
	case '.':		//output byte at pointer
	  putchar (*dp);
	  break;
	case ',':		//store byte input to byte at pointer
	  *dp = getchar ();
	  break;
	default:
	  break;
	}
    }
  fclose (fp);
  return 0;
}
Пример #3
0
void testSquaring()
{
	printf("Testing squaring\n");
	
	//Test 1
	
	// x^40 + x^7 + x^5 + x^3 + 1
	uint32_t input1[6] = { 0xA9, 0x100, 0x0, 0x0, 0x0, 0x0 };
	uint32_t result1[12];
	f2m_square(6, input1, result1);	
	// x^80 + x^14 + x^10 + x^6 + 1
	uint32_t validResult1[12] = { 0x4441, 0x0, 0x10000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
	assert(f2m_is_equal(12, result1, validResult1));
	
	//Test 2
	
	// x^112 + x^32 + x^16 + x^8 + x^4 + x^2 + x^1
	uint32_t input2[6] = { 0x10116, 0x1, 0x0, 0x10000, 0x0, 0x0 };
	uint32_t result2[12];
	f2m_square(6, input2, result2);
	// x^224 + x^64 + x^32 + x^16 + x^8 + x^4 + x^2
	uint32_t validResult2[12] = { 0x10114, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0 };
	assert(f2m_is_equal(12, result2, validResult2));
	
	//Test3
	
	// x^191 + x^112 + x^32 + x^30 + x^29 + x^27 + x^26 +x^23 +x^21 +x^18 +x^17 +x^14 +x^13 +x^12 +x^7 +x^6 + x^3 + x^2 +x^1 + 1
	uint32_t input3[6] = { 0x6CA670CF, 0x1, 0x0, 0x10000, 0x0, 0x80000000 };
	uint32_t result3[12];
	f2m_square(6, input3, result3);
	// x^382 + x^224 + x^64 + x^60 + x^58 +x^52 + x^46 + x^42 + x^38 + x^36  +x^34 + x^28 + x^26 + x^14 +x^12 + x^6 + x^4 + x^2 + 1 
	uint32_t validResult3[12] = { 0x15005055, 0x14504414, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x40000000 };
	
	assert(f2m_is_equal(12, result3, validResult3));
	
	uint32_t r24[24];
	initZero(24,r24);
	f2m_square(12, validResult3, r24);
	uint32_t vr24[24]  = {0x11001111,0x1110000,0x10100110,0x1101100,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000};
	
//	printf("\n validResult");
//	f2m_print_human(12,validResult3);
//	f2m_print_as_array(24,r24);
//	printf("\n");
//
//	printf("\n r\n");
//	f2m_print(24,r24);
//	printf("\n");
//	f2m_print_human(24,r24);
//	printf("\n vr\n");
//	f2m_print(24,vr24);
//	printf("\n");
//	f2m_print_human(24,vr24);
//	printf("\n");
	//assert(f2m_is_equal(24,r24,vr24));
	
	
	
	printf("Tests squaring passed\n");
}
Пример #4
0
// Initialize matrix and fill with 0
mat initNew(int n) {
	mat x = malloc(sizeof(double*) * n);
	x[0] = malloc(sizeof(double) * n * n);

    int i;
	for (i = 0; i < n; i++)
		x[i] = x[0] + n * i;
	initZero(x,n);

	return x;
}
Пример #5
0
void multvssqrt(){
	uint32_t *t = (uint32_t *) malloc((1)*sizeof(uint32_t));
	t[0] = 1;

	int testnr = 0;
	uint32_t* a = (uint32_t *) malloc((*t)*sizeof(uint32_t));
	a[0] =  a[0] = 0;

	while (*t < 4){
		uint32_t* ptr = shiftLeft(t,a,1);
		if (ptr){
			free(a);
			a = ptr;
		}
		a[*t-1] =  a[*t-1] ^ 0x1;
		uint32_t* result_mult   = (uint32_t *) malloc(2*(*t)*sizeof(uint32_t));
		uint32_t* result_sqrt   = (uint32_t *) malloc(2*(*t)*sizeof(uint32_t));
		initZero(2*(*t),result_mult);
		initZero(2*(*t),result_sqrt);

		f2m_mult (*t,a,a, result_mult);
		f2m_square(*t,a,result_sqrt);

		testeqprint("multvssqrt",testnr++,2*(*t),result_mult,result_sqrt);
		if (!f2m_is_equal(2*(*t),result_mult,result_sqrt)){
		    printf("\n    a: ");
		    f2m_print(*t,a);
		    printf("       ");
		    f2m_print_human(*t,a);
		    printf("\n       ");
		    f2m_print_as_array(*t,a);
			break;
		}
		free(result_mult);
		free(result_sqrt);
	}



}
Пример #6
0
bool StImagePlane::initSideBySide(const StImagePlane& theImageL,
                                  const StImagePlane& theImageR,
                                  const int theSeparationDx,
                                  const int theSeparationDy,
                                  const int theValue) {
    if(theImageL.isNull() || theImageR.isNull()) {
        // just ignore
        return true;
    }
    if(theImageL.getSizeX() != theImageR.getSizeX() ||
       theImageL.getSizeY() != theImageR.getSizeY()) {
        // currently unsupported operation
        return false;
    }
    size_t dxAbsPx = size_t(abs(theSeparationDx));
    size_t dxLeftRPx  = (theSeparationDx > 0) ?     dxAbsPx : 0;
    size_t dxLeftLPx  = (theSeparationDx < 0) ? 2 * dxAbsPx : 0;

    size_t dyAbsPx = size_t(abs(theSeparationDy));
    size_t dyTopLPx  = (theSeparationDy > 0) ? dyAbsPx : 0;
    size_t dyTopRPx  = (theSeparationDy < 0) ? dyAbsPx : 0;

    size_t outSizeX = (theImageL.getSizeX() + dxAbsPx) * 2;
    size_t outSizeY =  theImageL.getSizeY() + dyAbsPx  * 2;

    setFormat(theImageL.getFormat());
    if(!initZero(theImageL.getFormat(), outSizeX, outSizeY, outSizeX * theImageL.getSizePixelBytes(), theValue)) {
        return false;
    }

    // save cross-eyed
    for(size_t row = 0; row < theImageR.getSizeY(); ++row) {
        stMemCpy(changeData(dyTopRPx + row, dxLeftRPx),
                 theImageR.getData(row, 0),
                 theImageR.getSizeRowBytes());
    }
    for(size_t row = 0; row < theImageR.getSizeY(); ++row) {
        stMemCpy(changeData(dyTopLPx + row, theImageR.getSizeX() + dxLeftLPx + dxLeftRPx),
                 theImageL.getData(row, 0),
                 theImageL.getSizeRowBytes());
    }
    return true;
}
Пример #7
0
void multtest(){
  uint32_t t = 1;
  uint32_t testnr = 1;
  uint32_t z[1] = {0x0};
  uint32_t a[1] = {0x00000001};  //1
  uint32_t b[1] = {0x00000002};  //z
  uint32_t c[1] = {0x00000003};  //z+1
  uint32_t d[1] = {0x00000006};  
  uint32_t e[1] = {0x00000007}; //z^3+z+1 
  
  uint32_t f[1] = {0x80000000};
  uint32_t g[1] = {0x00000002};
  uint32_t h[2] = {0x0,0x00000001};





  uint32_t j[6] = { 0xA9, 0x100, 0x0, 0x0, 0x0, 0x0 };
  uint32_t k[12] = { 0x4441, 0x0, 0x10000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0  };
  uint32_t l[24] = { 0x10101001,0x0,0x0,0x0,0x0,0x00000001,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
  
  uint32_t m[12] = {0x15005055, 0x14504414, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x40000000 };
  uint32_t n[24] = {0x11001111,0x1110000,0x10100110,0x1101100,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000};

  uint32_t o[2]    = {0xF000000F,0xF000000F};
  uint32_t r4[4];
  uint32_t r4_2[4];

  initZero(4,r4);
  initZero(4,r4_2);

  f2m_mult(2,o,o,r4);
  f2m_square(2,o,r4_2);


  
  testeqprint("multtest",testnr++,4,r4,r4_2);

  uint32_t r1[1]  = {0x0};
  uint32_t r2[2]  = {0x0,0x0};
  uint32_t r12[12] ;
  initZero(12,r12);

  uint32_t r24[24] ;
  initZero(24,r24);



  

  f2m_mult (t,z,z, r1);
  testeqprint("multtest",testnr++,t,z,r1);
  initZero(t,r1);  

  f2m_mult (t,a,b, r1);
  testeqprint("multtest",testnr++,t,b,r1);
  initZero(t,r1);

  f2m_mult (t,a,c, r1);
  testeqprint("multtest",testnr++,t,c,r1);
  initZero(t,r1);

  f2m_mult (t,b,c, r1);
  testeqprint("multtest",testnr++,t,d,r1);
  initZero(t,r1); 
  
  f2m_mult (t,f,g, r2);
  testeqprint("multtest",testnr++,2,h,r2);
  initZero(t,r2); 


  f2m_mult (6,j,j, r12);
  testeqprint("multtest",testnr++,12,k,r12);
  initZero(12,r12);


  f2m_mult (12,k,k, r24);
  testeqprint("multtest",testnr++,24,l,r24);
  initZero(24,r24);

  f2m_mult (12,m,m, r24);
  testeqprint("multtest",testnr++,24,n,r24);
  initZero(24,r24);


  

}