⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idxiterators.hpp

📁 Gaussian Mixture Algorithm
💻 HPP
📖 第 1 页 / 共 2 页
字号:
ScalarIter<T>& ScalarIter<T>::operator++(){	if( this->isSimpleIteration ){		this->incr_contiguous();	}	else{		this->incr_noncontiguous();	}	return *this;}/// Postincrement operatortemplate<typename T>ScalarIter<T> ScalarIter<T>::operator++(int){	ScalarIter result(*this);	++this;	return result;}/// Predecrement operatortemplate<typename T>ScalarIter<T>& ScalarIter<T>::operator--(){	if( this->isSimpleIteration ){		this->decr_contiguous();	}	else{		this->decr_noncontiguous();	}	return *this;}/// Postdecrement operator.template<typename T>ScalarIter<T> ScalarIter<T>::operator--(int){	ScalarIter result(*this);	--this;	return result;}	//template<typename T>//RScalarIter<T>& //RScalarIter<T>::operator++(){//	switch(this->incrPolicy){//		case ScalarIter_Base<T>::CONTIGUOUS://			decr_contiguous();//			break;//		case ScalarIter_Base<T>::NONCONTIGUOUS://			decr_noncontiguous();//		default://			ylerror("Unrecognized IncrType.");//	}//	return *this;//}template<typename T>std::ostream& operator<<( std::ostream& out, ScalarIter_Base<T>& si ){	out<<"<ScalarIterator_Base  inds: ";	for( int dd = 0; dd < si.spec.getndim(); ++dd ){		out<<si.inds[dd]<<" ";	}	out<<" value = "<<*si<<">";	return out;}template<typename T>ReverseScalarIter<T>::ReverseScalarIter( Idx<T>& idx, bool isBeginning )	:ScalarIter_Base<T>(idx){	// set dataEnd	if( this->isSimpleIteration ){ // includes the case of ndim == 0		this->dataEnd = this->data - 1;	}	else{		this->dataEnd = NULL;	}			// set inds	if( this->isSimpleIteration ){		// set unused inds array to something deliberately and flagrantly bogus		this->inds[0] = std::numeric_limits<int>::max(); 	}	else{				if(isBeginning){			this->inds[0] = this->spec.dim[0]-1;		}		else{			this->inds[0] = -1;		}		for( int dd = 1; dd < this->spec.ndim; ++dd ){			this->inds[dd] = this->spec.dim[dd]-1;		}	}		// set data pointer	if( isBeginning ){		if( this->isSimpleIteration ){			this->data += this->spec.mod[0]*this->spec.dim[0] - 1;		}		else{			for( int dd = 0; dd < this->spec.ndim; ++dd ){				this->data += this->spec.mod[dd] * (this->spec.dim[dd] - 1);			}		}	}	else{		this->data = this->dataEnd;	}		}template<typename T>ReverseScalarIter<T>& ReverseScalarIter<T>::operator++(){	if( this->isSimpleIteration ){		this->decr_contiguous();	}	else{		this->decr_noncontiguous();	}	return *this;}/// Postincrement operatortemplate<typename T>ReverseScalarIter<T> ReverseScalarIter<T>::operator++(int){	ReverseScalarIter result(*this);	++this;	return result;}/// Predecrement operatortemplate<typename T>ReverseScalarIter<T>& ReverseScalarIter<T>::operator--(){		if( this->isSimpleIteration ){		this->incr_contiguous();	}	else{		this->incr_noncontiguous();	}	return *this;}/// Postdecrement operator.template<typename T>ReverseScalarIter<T> ReverseScalarIter<T>::operator--(int){	ReverseScalarIter result(*this);	--this;	return result;}template<typename T>DimIter_Base<T>::DimIter_Base(Idx<T>& idx, int dimInd)	: Idx<T>(idx.select((dimInd >= 0 ? dimInd : dimInd + idx.order()), 0))//	 dimInd(dimInd),//	 dimMod(idx.spec.mod[dimInd]),//	 dataEnd(idx.getstorage()->data + ( idx.spec.offset + //			 	 idx.spec.mod[dimInd] * idx.spec.dim[dimInd] ))	 //subtensor(idx.select(dimInd, 0)),//	 dataEnd(this->subtensor.getstorage()->data + //	 		 (this->subtensor.spec.offset + this->dimMod * idx.spec.dim[dimInd])){	if( dimInd < 0 ){		ylerror("DimIter_Base: negative looping dimension");		dimInd += idx.order();	}	//this->subtensor = idx.select(dimInd,0);	this->dimInd = dimInd;	this->dimMod = idx.spec.mod[dimInd];	this->dataEnd = idx.getstorage()->data + 			  		( idx.spec.offset + idx.spec.mod[dimInd] * idx.spec.dim[dimInd] );}template<typename T>DimIter_Base<T>::DimIter_Base( const DimIter_Base<T>& other )	:Idx<T>(other),	 dimInd(other.dimInd),	 dimMod(other.dimMod),	 //subtensor(*this),	 dataEnd(other.dataEnd)	 {}template<typename T>DimIter_Base<T>&DimIter_Base<T>::operator=( const DimIter_Base<T>& other ){	Idx<T>::operator=(other);	dimInd = other.dimInd;	dimMod = other.dimMod;	//subtensor = other.subtensor;	dataEnd = other.dataEnd;	return *this;}template<typename T>bool DimIter_Base<T>::operator==( const DimIter_Base& other ){	// like operator== in ScalarIter, this is lean and mean; no checks.	return this->getstorage()->data + this->spec.offset == other.storage->data + other.spec.offset;//	return subtensor.storage->data + subtensor.spec.offset == //		   other.storage->data + other.spec.offset;}template<typename T>Idx<T>& DimIter_Base<T>::operator*(){	return *this;	//return subtensor;}template<typename T>Idx<T>* DimIter_Base<T>::operator->(){	return this;	//return subtensor;}template<typename T>void DimIter_Base<T>::incr(){	this->spec.offset += this->dimMod;}template<typename T>void DimIter_Base<T>::decr(){	this->spec.offset -= this->dimMod; }template<typename T>bool DimIter_Base<T>::notdone(){	//return ind == dimSize;	//dataInd == dimSize	return (this->getstorage()->data + this->spec.offset) != this->dataEnd;}template<typename T>DimIter<T>::DimIter( Idx<T>& idx, int dimInd, bool isBeginning )	: DimIter_Base<T>(idx, dimInd){	if(!isBeginning){		// increment spec.offset so that the first Idx elemetn points to dataEnd		T* dataBegin = this->getstorage()->data + this->spec.offset;		this->spec.offset += std::distance( dataBegin, this->dataEnd );		assert(this->getstorage()->data + this->spec.offset == this->dataEnd);	}}template<typename T>DimIter<T>::DimIter(const DimIter<T>& other)	:DimIter_Base<T>(other){}template<typename T>DimIter<T>&DimIter<T>::operator=( const DimIter<T>& other ){	DimIter_Base<T>::operator=(other);	return *this;}template<typename T>DimIter<T>&DimIter<T>::operator++(){	this->incr();	return *this;}template<typename T>DimIter<T>DimIter<T>::operator++(int){	DimIter<T> returnVal(*this);	this->incr();	return returnVal;}template<typename T>DimIter<T>&DimIter<T>::operator--(){	this->decr();	return *this;}template<typename T>DimIter<T>DimIter<T>::operator--(int){	DimIter<T> returnVal(*this);	this->decr();	return returnVal;}template<typename T>boolDimIter<T>::operator==( const DimIter<T>& other ){	return DimIter_Base<T>::operator==(other);}template<typename T>ReverseDimIter<T>::ReverseDimIter( Idx<T>& idx, int dimInd, bool isBeginning )	:DimIter_Base<T>(idx, dimInd, isBeginning){	T* data = this->subtensor.storage()->data;	this->dataEnd = data - this->dimMod; 	if( !isBeginning ){		this->subtensor.storage()->data = this->dataEnd;	}}template<typename T>ReverseDimIter<T>::ReverseDimIter( const ReverseDimIter<T>& other )	:DimIter_Base<T>(other){}template<typename T>ReverseDimIter<T>&ReverseDimIter<T>::operator=( const ReverseDimIter<T>& other ){	DimIter_Base<T>::operator=(other);	return *this;}template<typename T>bool ReverseDimIter<T>::operator()(){	//return ind == dimSize;	//dataInd == dimSize	return this->subtensor.getstorage()->data + this->subtensor.spec.offset != this->dataEnd;}template<typename T>ReverseDimIter<T>&ReverseDimIter<T>::operator++(){	this->incr();	return *this;}template<typename T>ReverseDimIter<T>ReverseDimIter<T>::operator++(int){	ReverseDimIter<T> returnVal(*this);	this->incr();	return returnVal;}template<typename T>ReverseDimIter<T>&ReverseDimIter<T>::operator--(){	this->decr();	return *this;}template<typename T>ReverseDimIter<T>ReverseDimIter<T>::operator--(int){	ReverseDimIter<T> returnVal(*this);	this->decr();	return returnVal;}template<typename T>boolReverseDimIter<T>::operator==( const ReverseDimIter<T>& other ){	return DimIter_Base<T>::operator==(other);}} // end namespace ebl#endif /*IDXITER_HPP_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -