Esempio n. 1
0
long SchreyerFrame::computeNextLevel()
{
  if (currentLevel() == 1) return 0;
  if (currentLevel() >= mFrame.mLevels.size()) return 0;
  //  std::cout << "computeNextLevel: level = " << currentLevel() << std::endl;
  // loop through all the elements at level currentLevel()-2
  int level0 = currentLevel()-2;
  int level1 = level0+1;
  long n_elems_added = 0;
  for (auto i = level(level0).begin(); i != level(level0).end(); ++i)
    {
      long begin = (*i).mBegin;
      long end = (*i).mEnd;
      for (long i=begin; i<end; ++i)
        {
          auto& elem = level(level1)[i];
          elem.mBegin = n_elems_added;
          n_elems_added += computeIdealQuotient(level1, begin, i);
          elem.mEnd = n_elems_added;
        }
    }
  //show();
  setSchreyerOrder(mCurrentLevel);
  mCurrentLevel++;
  return n_elems_added;
}
Esempio n. 2
0
TSymbol *TSymbolTable::find(const TString &name, int shaderVersion,
                            bool *builtIn, bool *sameScope) const
{
    int level = currentLevel();
    TSymbol *symbol;

    do
    {
        if (level == ESSL3_1_BUILTINS && shaderVersion != 310)
            level--;
        if (level == ESSL3_BUILTINS && shaderVersion < 300)
            level--;
        if (level == ESSL1_BUILTINS && shaderVersion != 100)
            level--;

        symbol = table[level]->find(name);
    }
    while (symbol == 0 && --level >= 0);

    if (builtIn)
        *builtIn = (level <= LAST_BUILTIN_LEVEL);
    if (sameScope)
        *sameScope = (level == currentLevel());

    return symbol;
}
Esempio n. 3
0
long SchreyerFrame::computeIdealQuotient(int lev, long begin, long elem)
{
  ///  std::cout << "computeIdealQuotient(" << lev << "," << begin << "," << elem << ")" << std::endl;
  // Returns the number of elements added
  res_packed_monomial m = monomial(lev, elem); 
  std::vector<PreElement*> elements;
  if (ring().isSkewCommutative())
    {
      auto skewvars = new int[ring().monoid().n_vars()];
      int a = ring().monoid().skew_vars(ring().skewInfo(), m, skewvars);
      // std::cout << "adding " << a << " syz from skew" << std::endl;
      for (int i=0; i<a; ++i)
        {
          PreElement* vp = mPreElements.allocate();
          vp->vp = mVarpowers.reserve(mMaxVPSize);
          monoid().variable_as_vp(skewvars[i], vp->vp); 
          vp->degree = monoid().degree_of_vp(vp->vp);         
          int len = static_cast<int>(res_varpower_monomials::length(vp->vp));
          mVarpowers.intern(len);

          elements.push_back(vp);
        }
      delete [] skewvars;
    }
  for (long i=begin; i<elem; i++)
    elements.push_back(createQuotientElement(monomial(lev,i), m));
  typedef ResF4MonomialLookupTableT<int32_t> MonomialLookupTable;
  MonomialLookupTable montab(monoid().n_vars());

#if 0
  std::cout << "  #pre elements = " << elements.size() << std::endl;
  for (auto i=elements.begin(); i != elements.end(); ++i)
    {
      varpower_monomials::elem_text_out(stdout, (*i)->vp);
      fprintf(stdout, "\n");
    }
#endif
  PreElementSorter C;
  std::stable_sort(elements.begin(), elements.end(), C);

  long n_elems = 0;
  for (auto i = elements.begin(); i != elements.end(); ++i)
    {
      int32_t not_used;
      bool inideal = montab.find_one_divisor_vp(0, (*i)->vp, not_used);
      if (inideal) continue;
      // Now we create a res_packed_monomial, and insert it into 'lev+1'
      montab.insert_minimal_vp(0, (*i)->vp, 0);
      res_packed_monomial monom = monomialBlock().allocate(monoid().max_monomial_size());
      monoid().from_varpower_monomial((*i)->vp, elem, monom);
      // Now insert it into the frame
      insertBasic(currentLevel(), monom, (*i)->degree + degree(currentLevel()-1, monoid().get_component(monom)));
      n_elems++;
    }
  //std::cout << "  returns " << n_elems << std::endl;
  return n_elems;
}
Esempio n. 4
0
void State::setCurrentToLast(int size){
	int last = currentLevel().getLast();
	if(last >=0 && last < size)
		currentLevel().setCurrent(last);
	else if(last < 0)
		currentLevel().setCurrent(0);
	else if(last >=size)
		currentLevel().setCurrent(size-1);
}
Esempio n. 5
0
	void OGL2DTexture::copyFromFramebuffer(const ion_uint32 x,const ion_uint32 y)
	{
		glbind();

		if (!m_pDataSubmitted[currentLevel()]) {
			glCopyTexImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),m_Internalformat,x,y,
				m_LevelWidth,m_LevelHeight,0);
			m_pDataSubmitted[currentLevel()]=true;
		} else {
			glCopyTexSubImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),0,0,x,y,m_LevelWidth,m_LevelHeight);
		}
	}
Esempio n. 6
0
void TSymbolTable::dump(TInfoSink &infoSink) const
{
    for (int level = currentLevel(); level >= 0; --level) {
        infoSink.debug << "LEVEL " << level << "\n";
        table[level]->dump(infoSink);
    }
}
Esempio n. 7
0
void SchreyerFrame::show(int len) const
{
  std::cout << "#levels=" << mFrame.mLevels.size() << " currentLevel=" << currentLevel() << std::endl;
  for (int i=0; i<mFrame.mLevels.size(); i++)
    {
      auto& myframe = level(i);
      auto& myorder = schreyerOrder(i);
      if (myframe.size() == 0) continue;
      std::cout << "--- level " << i << " ------" << std::endl;
      for (int j=0; j<myframe.size(); j++)
        {
          std::cout << "    " << j << " " << myframe[j].mDegree 
                    << " (" << myframe[j].mBegin << "," << myframe[j].mEnd << ") " << std::flush;
          std::cout << "(size:" << myframe[j].mSyzygy.len << ") [";
          monoid().showAlpha(myorder.mTotalMonom[j]);
          std::cout << "  " << myorder.mTieBreaker[j] << "] ";
          if (len == 0 or myframe[j].mSyzygy.len == 0)
            monoid().showAlpha(myframe[j].mMonom);
          else
            display_poly(stdout, ring(), myframe[j].mSyzygy);
          std::cout << std::endl;
        }
    }
  showMemoryUsage();
}
Esempio n. 8
0
	void OGL2DTexture::unmap()
	{
		if (!m_IsMapped) return;

		GLenum format=oglrgbaformat(video::rgbalayoutFromPixelformat(m_Pixelformat));
		GLenum type=GL_UNSIGNED_BYTE; // TODO


		if (!m_pDataSubmitted[currentLevel()]) {
			glTexImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),m_Internalformat,
				m_LevelWidth,m_LevelHeight,0,format,type,pixeldata());
			m_pDataSubmitted[currentLevel()]=true;
		} else {
			glTexSubImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),0,0,m_LevelWidth,m_LevelHeight,
				format,type,pixeldata());
		}

		m_IsMapped=false;
	}
Esempio n. 9
0
	void Texture2D::generateMipmaps(const Picbuffer& src)
	{
		SimplePicbuffer tmp1(src.width(),src.height(),src.pixelformat());
		SimplePicbuffer tmp2(src);
		SimplePicbuffer *pTmp[2]={&tmp1,&tmp2};
		int i=0;

		for (ion_uint32 lvl=0;lvl<numMipmaplevels();++lvl) {
			currentLevel(lvl);

			pTmp[i]->resizeDimensions(this->width(),this->height());
			pTmp[i]->transfer(*(pTmp[1-i]));
			
			map();
			transfer(*(pTmp[i]));
			unmap();

			i=1-i;
		}
	}
Esempio n. 10
0
void LocalController::swapLevel(Level& newLevel)
{
	currentLevel()->swap(newLevel);
}
Esempio n. 11
0
	OGL2DTexture::OGL2DTexture(OGLDevice& ogldevice,const base::String& identifier,
			const ion_uint32 width,const ion_uint32 height,const ion_uint32 levels,const ion_uint32 flags,const video::Pixelformat format,
			const video::Memorypool pool):video::Texture2D(format,identifier,flags),m_rOGLDevice(ogldevice),m_IsValid(true),
			m_IsDataOK(true),m_IsMapped(false),m_GLHandle(0),m_Framebuffer(0),m_DepthRenderbuffer(0),
			m_StencilRenderbuffer(0),m_LevelWidth(0),m_LevelHeight(0),m_MappedLevel(0),m_CurrentLevel(0xffffffff)/*,
			m_Picbuffer(width,height,ogl2dtexformat(format))*/
	{
		if (!video::isDepthformat(format)) {
			glGenTextures(1,&m_GLHandle);
		}

		m_pSurfaces=0;

		m_OGLTexture.target(GL_TEXTURE_2D);
		m_OGLTexture.handle(m_GLHandle);

		ion_uint32 actualwidth=width,actualheight=height;

		if (!ISPOW2(actualwidth)) actualwidth=nextpow2(actualwidth);
		if (!ISPOW2(actualheight)) actualheight=nextpow2(actualheight);

		if (actualwidth!=actualheight) {
			ion_uint32 i=(actualwidth>actualheight) ? actualwidth : actualheight;
			actualwidth=actualheight=i;
		}

		m_pPicbuffer= ::new video::SimplePicbuffer(actualwidth,actualheight,ogl2dtexformat(format));

		m_Width=actualwidth;
		m_Height=actualheight;
		m_Pixelformat=m_pPicbuffer->pixelformat();
		m_NumMipmaplevels=levels;

		m_Internalformat=oglpixelformat(format);

		if (ogldevice.extensionSupported("GL_EXT_framebuffer_object")) {
			if (video::isDepthformat(format)) {
				if (ogldevice.extensionSupported("GL_ARB_depth_texture")) {
					GLenum depthformat=GL_DEPTH_COMPONENT24_ARB;
					switch (format) {
						case video::Pixelformat_D15S1:
						case video::Pixelformat_D16:
							depthformat=GL_DEPTH_COMPONENT16_ARB;
							break;
						case video::Pixelformat_D24:
						case video::Pixelformat_D24S4:
						case video::Pixelformat_D24S8:
						case video::Pixelformat_FD24S8:
							depthformat=GL_DEPTH_COMPONENT24_ARB;
							break;
						case video::Pixelformat_D32:
							depthformat=GL_DEPTH_COMPONENT32_ARB;
							break;
						default:break;
					}
	
					// TODO: depthstencil formats
	
					glGenRenderbuffersEXT(1,&m_DepthRenderbuffer);
					glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,m_DepthRenderbuffer);
					glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24_ARB,width,height);
					glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,0);

					m_NumMipmaplevels=1;

					m_pSurfaces=new OGL2DSurface[1];
					m_pSurfaces[0].m_pOGL2DTexture=this;
					m_pSurfaces[0].m_pTexture=this;
					m_pSurfaces[0].m_Level=0;
					m_pSurfaces[0].m_GLHandle=0;
					m_pSurfaces[0].m_Width=actualwidth;
					m_pSurfaces[0].m_Height=actualheight;
					m_pSurfaces[0].m_DepthRenderbuffer=m_DepthRenderbuffer;
					m_pSurfaces[0].m_Framebuffer=0;
					m_pSurfaces[0].m_StencilRenderbuffer=0;

				} else m_IsValid=false;
			} else if (flags&video::Textureflag_IsRendertaget) {
				glGenFramebuffersEXT(1,&m_Framebuffer);

				glBindTexture(GL_TEXTURE_2D,m_GLHandle); // TODO: Save bound textures and restore them afterwards

				GLenum format=oglrgbaformat(video::rgbalayoutFromPixelformat(m_Pixelformat));
				GLenum type=GL_UNSIGNED_BYTE; // TODO

				m_NumMipmaplevels=1; // TODO: Support mipmaps in rendertargets

				m_pSurfaces=new OGL2DSurface[1];
				m_pSurfaces[0].m_pOGL2DTexture=this;
				m_pSurfaces[0].m_pTexture=this;
				m_pSurfaces[0].m_Level=0;
				m_pSurfaces[0].m_GLHandle=m_GLHandle;
				m_pSurfaces[0].m_Width=actualwidth;
				m_pSurfaces[0].m_Height=actualheight;
				m_pSurfaces[0].m_DepthRenderbuffer=0;
				m_pSurfaces[0].m_Framebuffer=m_Framebuffer;
				m_pSurfaces[0].m_StencilRenderbuffer=0;

				glTexImage2D(GL_TEXTURE_2D,0,m_Internalformat,width,height,0,format,type,0);

				glBindTexture(GL_TEXTURE_2D,0);
			}
		} else if (video::isDepthformat(format) || (flags&video::Textureflag_IsRendertaget)) {
			m_IsValid=false;
		}

		if (m_GLHandle!=0) {
			glbind();
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,(levels==1) ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			if (levels>1) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,levels-1);
		}

		if (m_NumMipmaplevels==0) {
			ion_uint32 length=(actualwidth<actualheight) ? actualwidth : actualheight;

			if (length<=1) m_NumMipmaplevels=1;
			else {
				m_NumMipmaplevels=((ion_uint32)( logf((float)length)/logf(2.0f) )) + 1;
			}
		}

		m_OGLTexture.numLevels(m_NumMipmaplevels);

		m_pDataSubmitted=new bool[m_NumMipmaplevels];
		for (ion_uint32 lvl=0;lvl<m_NumMipmaplevels;++lvl) m_pDataSubmitted[lvl]=false;

		currentLevel(0);
	}
Esempio n. 12
0
	void OGL2DTexture::map()
	{
		if (m_IsMapped) return;
		m_MappedLevel=currentLevel();
		m_IsMapped=true;
	}
Esempio n. 13
0
int WorkingBuffers::currentStyleHeight(int styleIndex) const
{
    return DataAccess::instance().getStyleHeight(styleIndex) >> currentLevel();
}
//Returns a full matrix containing the density matrix at the final time
inline matrix<std::complex<double> > RobustGrape::GetPopulations (const size_t point, size_t initial_level){
	//the measure implemented, phi (PHI_0) is phi = trace[rho_desired* UN-1....U_0 rho_initial U_0\dg ... U_N-1\dg]
	char outfile[50];
	//Some flags to make sure all parameters are set
	size_t test=0;
	for(size_t k = 0; k < num_controls_; ++k)
	{
		test+=controlsetflag_[k];
		if(verbose==yes)
		{
		 	std::cout << k << "th control flag is " << controlsetflag_[k] << std::endl;
		}
	}
	if(test != 0)
		UFs::MyError("Grape::StateTransfer(): you have not set the drift and all control hamiltonians:\n");
		
	
	//Set the counters to zero
	count_ =0;
	pos_count_ =0;
	//the power scale for epsilot (epsilon = base_a^power_)
	power_ =0;
	// fidelity ranges from 0 to 1 with 0 be orthogonal and 1 being the same time
	double current_fidelity=0.0, current_delta_fidelity=1.0, last_fidelity=-1.0;
		
	// the propagators and the foraward evolution
	for(size_t j = 0; j < num_time_; ++j){
		Htemp_ = H_drift_[point];
		for(size_t k = 0; k < num_controls_; ++k){
			Htemp_ += controls_[k][j]*H_controls_[point][k];
		}
		// std::cout << Htemp_ << std::endl;
		Unitaries_[point][j]=ExpM::EigenMethod(Htemp_,-i*h_);
		if(j==0){
			rho_[point][0] = Unitaries_[point][0]*rho_initial_*MOs::Dagger(Unitaries_[point][0]);
		}
		else{
			rho_[point][j] = Unitaries_[point][j]*rho_[point][j-1]*MOs::Dagger(Unitaries_[point][j]);
		}
	}
		
	//Initialize the matrices used to compute the populations
	matrix<std::complex<double> > populations;
	populations.initialize(num_time_,dim_);

	matrix<std::complex<double> > level, propagator, currentLevel, level2, step, tempMatrix, tempMatrix2;
	level.initialize(dim_,dim_);
	MOs::Null(level);
	
	propagator.initialize(dim_,dim_);
	MOs::Null(propagator);
	
	currentLevel.initialize(dim_, 1);
	MOs::Null(currentLevel);
	
	level2.initialize(dim_, 1);
	MOs::Null(level2);
	
	step.initialize(dim_, 1);
	MOs::Null(step);
	
	tempMatrix.initialize(1, 1);
	MOs::Null(tempMatrix);
	
	tempMatrix2.initialize(1, dim_);
	MOs::Null(tempMatrix2);

	
	for (int i=0; i < dim_; i++)
	{
		level(i, dim_-i-1)=1;
	}
	//Create the initial state selection vector 
	level2(dim_ - initial_level -1, 0)=1;
	
	for (int k=0; k < num_time_; k++)	//Go through each time step
	{
		step=propagator*level2;
		
		for (int j=0; j < dim_; j++)	//Go through each quantum level
		{
			MOs::Null(currentLevel);		
			currentLevel(dim_ -j -1, 0)=1;
			tempMatrix2=MOs::Dagger(currentLevel * step);
			tempMatrix=MOs::Dagger(currentLevel * step)*(currentLevel * step);
			populations(k,j)=tempMatrix(0,0);	//Time=row, Level=col			//This is the occupancy of each level
			//populations[j](0,k)=tempMatrix(0,0);	//Time=Columns, Level=row 
		}
	
		if (k!=num_time_) propagator = rho_[point][k] * propagator;
		if (verbose==yes)
		{
			std::cout << "--------------------Propogator------------------------------" << std::endl;
			USs::OutputMatrix(propagator);
			std::cout << "------------------------------------------------------------" << std::endl;
		}
	} 
	
	return populations;
	//Output the populations to file
//	string line;
//	ofstream moredataout (outfile, ios::app);
//	for(size_t j = 0; j < num_time_; ++j)	//Go through each time step
//	{
//		line=j*h_;
//		for (size_t i=0; i < dim_; i++)			//Go through each dimension of the Hilbert space
//		{
//			line=line "\t" + populations[i](0,j);
//		}
//		//Output line to file
//		moredataout << line << '\n';
//	}
	
//	dataout.close();
}