bugfix in permutation of smatrix

This commit is contained in:
Jiri Pittner 2023-07-28 15:38:24 +02:00
parent 9d51ef6fbd
commit ec42999812
2 changed files with 26 additions and 6 deletions

28
smat.cc
View File

@ -311,13 +311,35 @@ const NRSMat<T> NRSMat<T>::permuted(const NRPerm<int> &p, const bool inverse) co
if(!p.is_valid()) laerror("invalid permutation of smatrix"); if(!p.is_valid()) laerror("invalid permutation of smatrix");
#endif #endif
int n=p.size(); int n=p.size();
if(n!=(*this).size()) laerror("incompatible permutation and smatrix"); if(n!=(*this).nrows()) laerror("incompatible permutation and smatrix");
#ifdef CUDALA #ifdef CUDALA
if(this->getlocation() != cpu || p.getlocation() != cpu ) laerror("permutations can be done only in CPU memory"); if(this->getlocation() != cpu || p.getlocation() != cpu ) laerror("permutations can be done only in CPU memory");
#endif #endif
NRSMat<T> r(n); NRSMat<T> r(n);
if(inverse) for(int i=1; i<=n; ++i) {int pi = p[i]-1; r(i-1,i-1) = (*this)(pi,pi);} if(inverse)
else for(int i=1; i<=n; ++i) {int pi = p[i]-1; r(pi,pi) = (*this)(i-1,i-1);} {
for(int i=1; i<=n; ++i)
{
int pi = p[i]-1;
for(int j=1; j<=i; ++j)
{
int pj = p[j] - 1;
r(i-1,j-1) = (*this)(pi,pj);
}
}
}
else
{
for(int i=1; i<=n; ++i)
{
int pi = p[i]-1;
for(int j=1; j<=i; ++j)
{
int pj = p[j] - 1;
r(pi,pj) = (*this)(i-1,j-1);
}
}
}
return r; return r;
} }

4
t.cc
View File

@ -2760,9 +2760,7 @@ cout <<"Clique cover is "<<cover<<endl;
NRPerm<int> p(cover.size()); NRPerm<int> p(cover.size());
cover.sort(0,p); cover.sort(0,p);
cout<<"permutation to disentabgle the cliques = "<<p<<endl; cout<<"permutation to disentabgle the cliques = "<<p<<endl;
NRVec<int> perm1(p.size()); NRSMat<char> adjperm = adj.permuted(p);
for(int i=0; i<p.size(); ++i) perm1[i] = p[i+1]-1;
NRSMat<char> adjperm = adj.submatrix(perm1);
cout <<"resorted graph = "<<adjperm<<endl; cout <<"resorted graph = "<<adjperm<<endl;
} }