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