/* LA: linear algebra C++ interface library Copyright (C) 2021 Jiri Pittner or This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "permutation.h" namespace LA { template bool NRPerm::is_valid() const { T n = this->size(); if(n<0) return 0; NRVec_from1 used(n); used.clear(); for(T i=1; i<=n; ++i) { T x= (*this)[i]; if(x<1||x>n) return 0; used[x] += 1; } for(T i=1; i<=n; ++i) if(used[i]!=1) return 0; return 1; } template NRPerm NRPerm::inverse() const { NRPerm q(this->size()); for(T i=1; i<=this->size(); ++i) q[(*this)[i]]=i; return q; } template NRPerm NRPerm::operator*(const NRPerm q) const { T n=this->size(); if(n!=q.size()) laerror("product of incompatible permutations"); NRPerm r(n); for(T i=1; i<=n; ++i) r[i] = q[(*this)[i]]; return r; } /***************************************************************************//** * forced instantization in the corresponding object file ******************************************************************************/ template class NRPerm; }