application of a permutation on sparsemat
This commit is contained in:
		
							parent
							
								
									9ce8e74e19
								
							
						
					
					
						commit
						4c1aa07acf
					
				@ -199,8 +199,8 @@ template <typename T>
 | 
				
			|||||||
PERM_RANK_TYPE NRPerm<T>::generate_all(void (*callback)(const NRPerm<T>&), int select)
 | 
					PERM_RANK_TYPE NRPerm<T>::generate_all(void (*callback)(const NRPerm<T>&), int select)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
int n=this->size();
 | 
					int n=this->size();
 | 
				
			||||||
NRVec_from1<T> c(0,n);
 | 
					NRVec_from1<T> c((T)0,n);
 | 
				
			||||||
NRVec_from1<T> d(1,n);
 | 
					NRVec_from1<T> d((T)1,n);
 | 
				
			||||||
int j,k,s;
 | 
					int j,k,s;
 | 
				
			||||||
T q;
 | 
					T q;
 | 
				
			||||||
T t;
 | 
					T t;
 | 
				
			||||||
@ -480,7 +480,7 @@ CyclePerm<T>:: CyclePerm(const NRPerm<T> &p)
 | 
				
			|||||||
        if(!p.is_valid()) laerror("invalid permutation");
 | 
					        if(!p.is_valid()) laerror("invalid permutation");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
T n=p.size();
 | 
					T n=p.size();
 | 
				
			||||||
NRVec_from1<T> used(0,n),tmp(n);
 | 
					NRVec_from1<T> used((T)0,n),tmp(n);
 | 
				
			||||||
T firstunused=1;
 | 
					T firstunused=1;
 | 
				
			||||||
T currentcycle=0;
 | 
					T currentcycle=0;
 | 
				
			||||||
std::list<NRVec_from1<T> > cyclelist;
 | 
					std::list<NRVec_from1<T> > cyclelist;
 | 
				
			||||||
@ -1097,11 +1097,11 @@ if(!is_standard()) laerror("nonstandardly filled young frame");
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(!ncyc) ncyc=max(); //number of types of applied points
 | 
					if(!ncyc) ncyc=max(); //number of types of applied points
 | 
				
			||||||
NRVec_from1<T> onxlines(0,ncyc);
 | 
					NRVec_from1<T> onxlines((T)0,ncyc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for(int i=1;i<=(*this).size();i++) //rows
 | 
					for(int i=1;i<=(*this).size();i++) //rows
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
	NRVec_from1<T> wasfound(0,ncyc);
 | 
						NRVec_from1<T> wasfound((T)0,ncyc);
 | 
				
			||||||
        for(int j=1;j<=(*this)[i].size();j++) //columns
 | 
					        for(int j=1;j<=(*this)[i].size();j++) //columns
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                T k = (*this)[i][j];
 | 
					                T k = (*this)[i][j];
 | 
				
			||||||
@ -1177,7 +1177,7 @@ if the application was successfull at all and return back or call nextapply, res
 | 
				
			|||||||
Partition<T> usedcols(_nn<T>),usedlines(_nn<T>); //stores the positions where points were placed, is necessary for later cleanup
 | 
					Partition<T> usedcols(_nn<T>),usedlines(_nn<T>); //stores the positions where points were placed, is necessary for later cleanup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*try to place first point*/
 | 
					/*try to place first point*/
 | 
				
			||||||
for(usedlines[1]=mymin(_tchi<T>->nrows(),(*_occol<T>)[1]+napl); usedlines[1]>0; usedlines[1]--)
 | 
					for(usedlines[1]=mymin((T)_tchi<T>->nrows(),(*_occol<T>)[1]+napl); usedlines[1]>0; usedlines[1]--)
 | 
				
			||||||
   {
 | 
					   {
 | 
				
			||||||
   if((*_oclin<T>)[usedlines[1]]<=(*_tchi<T>)[usedlines[1]].size()) /*line is not fully occupied*/
 | 
					   if((*_oclin<T>)[usedlines[1]]<=(*_tchi<T>)[usedlines[1]].size()) /*line is not fully occupied*/
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -1379,7 +1379,7 @@ if(ilin > (*_tyou_cols<T>)[1])
 | 
				
			|||||||
	++_nyoungterms;
 | 
						++_nyoungterms;
 | 
				
			||||||
	(*_young_operator_callback<T>)(_aperm<T>*_sperm<T>,_antparity<T>,_expectterms);
 | 
						(*_young_operator_callback<T>)(_aperm<T>*_sperm<T>,_antparity<T>,_expectterms);
 | 
				
			||||||
	} 
 | 
						} 
 | 
				
			||||||
else if(iel > (*_tyou_rows<T>)[ilin]) symetr(ilin+1,1);
 | 
					else if(iel > (*_tyou_rows<T>)[ilin]) symetr(ilin+1,(T)1);
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
@ -1407,7 +1407,7 @@ if(icol > (*_tyou_rows<T>)[1])
 | 
				
			|||||||
	symetr<T>(1,1);
 | 
						symetr<T>(1,1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
if(iel > (*_tyou_cols<T>)[icol]) antisym(icol+1,1);
 | 
					if(iel > (*_tyou_cols<T>)[icol]) antisym(icol+1,(T)1);
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
@ -1602,14 +1602,14 @@ return s;
 | 
				
			|||||||
/***************************************************************************//**
 | 
					/***************************************************************************//**
 | 
				
			||||||
 * forced instantization in the corresponding object file
 | 
					 * forced instantization in the corresponding object file
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
template class NRPerm<int>;
 | 
					 | 
				
			||||||
template class CyclePerm<int>;
 | 
					 | 
				
			||||||
template class CompressedPartition<int>;
 | 
					 | 
				
			||||||
template class Partition<int>;
 | 
					 | 
				
			||||||
template class YoungTableaux<int>;
 | 
					 | 
				
			||||||
template class Sn_characters<int>;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define INSTANTIZE(T) \
 | 
					#define INSTANTIZE(T) \
 | 
				
			||||||
 | 
					template class NRPerm<T>; \
 | 
				
			||||||
 | 
					template class CyclePerm<T>; \
 | 
				
			||||||
 | 
					template class CompressedPartition<T>; \
 | 
				
			||||||
 | 
					template class Partition<T>; \
 | 
				
			||||||
 | 
					template class YoungTableaux<T>; \
 | 
				
			||||||
 | 
					template class Sn_characters<T>; \
 | 
				
			||||||
template std::istream & operator>>(std::istream &s, CyclePerm<T> &x); \
 | 
					template std::istream & operator>>(std::istream &s, CyclePerm<T> &x); \
 | 
				
			||||||
template std::ostream & operator<<(std::ostream &s, const CyclePerm<T> &x); \
 | 
					template std::ostream & operator<<(std::ostream &s, const CyclePerm<T> &x); \
 | 
				
			||||||
template std::ostream & operator<<(std::ostream &s, const CompressedPartition<T> &x); \
 | 
					template std::ostream & operator<<(std::ostream &s, const CompressedPartition<T> &x); \
 | 
				
			||||||
@ -1619,6 +1619,7 @@ template std::ostream & operator<<(std::ostream &s, const Sn_characters<T> &x);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INSTANTIZE(int)
 | 
					INSTANTIZE(int)
 | 
				
			||||||
 | 
					INSTANTIZE(unsigned int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										72
									
								
								sparsemat.cc
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								sparsemat.cc
									
									
									
									
									
								
							@ -1060,6 +1060,8 @@ void SparseMat<T>::permuterows(const NRVec<SPMatindex> &p)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuterows");
 | 
					if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuterows");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
matel<T> *l=list;
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while(l)
 | 
					while(l)
 | 
				
			||||||
@ -1074,7 +1076,9 @@ while(l)
 | 
				
			|||||||
template<class T>
 | 
					template<class T>
 | 
				
			||||||
void SparseMat<T>::permutecolumns(const NRVec<SPMatindex> &p)
 | 
					void SparseMat<T>::permutecolumns(const NRVec<SPMatindex> &p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuterows");
 | 
					if((SPMatindex)p.size()!=mm) laerror("inconsistent dimension in permuterows");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
matel<T> *l=list;
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1089,7 +1093,9 @@ while(l)
 | 
				
			|||||||
template<class T>
 | 
					template<class T>
 | 
				
			||||||
void SparseMat<T>::permuteindices(const NRVec<SPMatindex> &p)
 | 
					void SparseMat<T>::permuteindices(const NRVec<SPMatindex> &p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuterows");
 | 
					if((SPMatindex)p.size()!=nn||(SPMatindex)p.size()!=mm) laerror("inconsistent dimension in permuterows");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
matel<T> *l=list;
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1102,6 +1108,68 @@ while(l)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//these assume both matrix and permutation indexed from 1
 | 
				
			||||||
 | 
					template<class T>
 | 
				
			||||||
 | 
					void SparseMat<T>::permuteme_rows(const NRPerm<int> &p, const bool inverse)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuteme_rows");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NRPerm<int> pp;
 | 
				
			||||||
 | 
					if(inverse) pp=p.inverse(); else pp=p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while(l)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						l->row = (SPMatindex) pp[(int)l->row];
 | 
				
			||||||
 | 
						if(symmetric) l->col= (SPMatindex) pp[(int)l->col];
 | 
				
			||||||
 | 
						l=l->next;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<class T>
 | 
				
			||||||
 | 
					void SparseMat<T>::permuteme_cols(const NRPerm<int> &p, const bool inverse)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					if((SPMatindex)p.size()!=nn) laerror("inconsistent dimension in permuteme_cols");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NRPerm<int> pp;
 | 
				
			||||||
 | 
					if(inverse) pp=p.inverse(); else pp=p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while(l)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						l->col = (SPMatindex) pp[(int)l->col];
 | 
				
			||||||
 | 
						if(symmetric) l->row= (SPMatindex) pp[(int)l->row];
 | 
				
			||||||
 | 
						l=l->next;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<class T>
 | 
				
			||||||
 | 
					void SparseMat<T>::permuteme_both(const NRPerm<int> &p, const NRPerm<int> &q, const bool inverse)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					if((SPMatindex)p.size()!=nn || (SPMatindex)q.size()!=mm) laerror("inconsistent dimension in permuteme_both");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					copyonwrite();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					matel<T> *l=list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NRPerm<int> pp, qq;
 | 
				
			||||||
 | 
					if(inverse) pp=p.inverse(); else pp=p;
 | 
				
			||||||
 | 
					if(inverse) qq=q.inverse(); else qq=q;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while(l)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        l->row= (SPMatindex) pp[(int)l->row];
 | 
				
			||||||
 | 
					        l->col= (SPMatindex) qq[(int)l->col];
 | 
				
			||||||
 | 
					        l=l->next;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<class T>
 | 
					template<class T>
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								sparsemat.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								sparsemat.h
									
									
									
									
									
								
							@ -124,9 +124,15 @@ public:
 | 
				
			|||||||
	void incsize(const SPMatindex n, const SPMatindex m); //increase size without destroying the data
 | 
						void incsize(const SPMatindex n, const SPMatindex m); //increase size without destroying the data
 | 
				
			||||||
	void transposeme();
 | 
						void transposeme();
 | 
				
			||||||
	const SparseMat transpose() const;
 | 
						const SparseMat transpose() const;
 | 
				
			||||||
	void permuteindices(const NRVec<SPMatindex> &p);
 | 
						void permuteindices(const NRVec<SPMatindex> &p); //for backward compatibility, indices from 0
 | 
				
			||||||
	void permuterows(const NRVec<SPMatindex> &p);
 | 
						void permuterows(const NRVec<SPMatindex> &p); //for backward compatibility, indices from 0
 | 
				
			||||||
	void permutecolumns(const NRVec<SPMatindex> &p);
 | 
						void permutecolumns(const NRVec<SPMatindex> &p); //for backward compatibility, indices from 0
 | 
				
			||||||
 | 
						void permuteme_rows(const NRPerm<int> &p, const bool inverse=false); //indexed from 1
 | 
				
			||||||
 | 
						void permuteme_cols(const NRPerm<int> &p, const bool inverse=false); //indexed from 1
 | 
				
			||||||
 | 
						void permuteme_both(const NRPerm<int> &p, const NRPerm<int> &q, const bool inverse=false); //indexed from 1
 | 
				
			||||||
 | 
						const SparseMat permuted_rows(const NRPerm<int> &p, const bool inverse=false) const {SparseMat a(*this); a.permuteme_rows(p,inverse); return a;};
 | 
				
			||||||
 | 
						const SparseMat permuted_cols(const NRPerm<int> &p, const bool inverse=false) const {SparseMat a(*this); a.permuteme_cols(p,inverse); return a;};
 | 
				
			||||||
 | 
						const SparseMat permuted_both(const NRPerm<int> &p, const NRPerm<int> &q, const bool inverse=false) const {SparseMat a(*this); a.permuteme_both(p,q,inverse); return a;};
 | 
				
			||||||
	inline void setsymmetric() {if(nn!=mm) laerror("non-square cannot be symmetric"); symmetric=1;}
 | 
						inline void setsymmetric() {if(nn!=mm) laerror("non-square cannot be symmetric"); symmetric=1;}
 | 
				
			||||||
	inline void defineunsymmetric() {symmetric=0;} //just define and do nothing with it
 | 
						inline void defineunsymmetric() {symmetric=0;} //just define and do nothing with it
 | 
				
			||||||
	void setunsymmetric();//unwind the matrix assuming it was indeed symmetric
 | 
						void setunsymmetric();//unwind the matrix assuming it was indeed symmetric
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user