matrix of permutationalgebra and type conversions

This commit is contained in:
Jiri Pittner 2024-01-18 15:50:11 +01:00
parent 8f61a5d208
commit 680fa93425
4 changed files with 55 additions and 0 deletions

21
mat.cc
View File

@ -3173,6 +3173,27 @@ T alpha= parity? p.parity():1;
axpy(alpha,p,direction);
}
template<typename T>
NRMat<T>::NRMat(const WeightPermutation<int,T> &wp, const bool direction)
{
int n=wp.size();
resize(n,n);
clear();
axpy(wp.weight,wp.perm,direction);
}
template<typename T>
NRMat<T>::NRMat(const PermutationAlgebra<int,T> &ap, const bool direction)
{
int na= ap.size();
if(na<=0) laerror("cannot deduce matrix size from empty PermutationAlgebra");
int n=ap[0].size();
resize(n,n);
clear();
for(int i=0; i<na; ++i) axpy(ap[i].weight,ap[i].perm,direction);
}
//apply permutations

15
mat.h
View File

@ -31,6 +31,8 @@ namespace LA {
//forward declaration
template<typename T> class NRPerm;
template<typename T, typename R> class WeightPermutation;
template<typename T, typename R> class PermutationAlgebra;
template<typename T> class CyclePerm;
template<typename T> class NRMat_from1;
@ -136,6 +138,8 @@ public:
void scale_col(const int i, const T f); //in place
void axpy(const T alpha, const NRPerm<int> &p, const bool direction);
explicit NRMat(const NRPerm<int> &p, const bool direction, const bool parity=false); //permutation matrix
explicit NRMat(const WeightPermutation<int,T> &p, const bool direction);
explicit NRMat(const PermutationAlgebra<int,T> &p, const bool direction);
/***************************************************************************//**
@ -1556,6 +1560,17 @@ NRMat<typename LA_traits<T>::normtype> NRMat<T>::abs() const {
}
//convert whole matrix between types
template <typename T, typename S>
void NRMat_convert(NRMat<T> &a, const NRMat<S> &b)
{
a.resize(b.nrows(),b.ncols());
for(int i=0; i<b.nrows(); ++i)
for(int j=0; j<b.ncols(); ++j)
a(i,j) = (T) b(i,j);
}

10
smat.h
View File

@ -1223,6 +1223,16 @@ std::istream& operator>>(std::istream &s, NRSMat<T> &x) {
#endif
}
//convert whole matrix between types
template <typename T, typename S>
void NRSMat_convert(NRSMat<T> &a, const NRSMat<S> &b)
{
a.resize(b.nrows(),b.ncols());
for(int i=0; i<b.nrows(); ++i)
for(int j=0; j<=i; ++j)
a(i,j) = (T) b(i,j);
}
/***************************************************************************//**
* generate operators relating NRSMat<T> objects and scalars

9
vec.h
View File

@ -2039,6 +2039,15 @@ for(int next=0; next<newsize; ++next)
x.resize(newsize2,true);
}
//convert whole vector between types
template <typename T, typename S>
void NRVec_convert(NRVec<T> &a, const NRVec<S> &b)
{
a.resize(b.size());
for(int i=0; i<b.size(); ++i)
a[i] = (T) b[i];
}
}//namespace