contructors from braced list for permutations and polynomials
This commit is contained in:
parent
d96531f340
commit
9c6ab037cf
1
mat.h
1
mat.h
@ -1325,6 +1325,7 @@ template<typename T>
|
||||
class NRMat_from1 : public NRMat<T> {
|
||||
public:
|
||||
NRMat_from1(): NRMat<T>() {};
|
||||
template<int R, int C> explicit NRMat_from1(const T (&a)[R][C]) : NRMat<T>(a) {};
|
||||
explicit NRMat_from1(const int n): NRMat<T>(n) {};
|
||||
explicit NRMat_from1(const NRSMat_from1<T> &rhs) : NRMat<T>(rhs) {};
|
||||
NRMat_from1(const NRMat<T> &rhs): NRMat<T>(rhs) {};//!< be able to convert the parent class transparently to this
|
||||
|
@ -41,6 +41,7 @@ class NRPerm : public NRVec_from1<T> {
|
||||
public:
|
||||
//basic constructors
|
||||
NRPerm(): NRVec_from1<T>() {};
|
||||
template<int SIZE> explicit NRPerm(const T (&a)[SIZE]) : NRVec_from1<T>(a) {};
|
||||
NRPerm(const int n) : NRVec_from1<T>(n) {};
|
||||
NRPerm(const NRVec_from1<T> &rhs): NRVec_from1<T>(rhs) {};
|
||||
NRPerm(const T *a, const int n): NRVec_from1<T>(a, n) {};
|
||||
@ -74,6 +75,8 @@ template <typename T>
|
||||
class CyclePerm : public NRVec_from1<NRVec_from1<T> > {
|
||||
public:
|
||||
CyclePerm() : NRVec_from1<NRVec_from1<T> >() {};
|
||||
template<int SIZE> explicit CyclePerm(const NRVec_from1<T> (&a)[SIZE]) : NRVec_from1<NRVec_from1<T> >(a) {};
|
||||
//NOTE - how to do it so that direct nested brace initializer would work?
|
||||
explicit CyclePerm(const NRPerm<T> &rhs);
|
||||
|
||||
bool is_valid() const; //is it really a permutation
|
||||
@ -132,6 +135,7 @@ template <typename T>
|
||||
class CompressedPartition : public NRVec_from1<T> {
|
||||
public:
|
||||
CompressedPartition(): NRVec_from1<T>() {};
|
||||
template<int SIZE> explicit CompressedPartition(const T (&a)[SIZE]) : NRVec_from1<T>(a) {};
|
||||
CompressedPartition(const int n) : NRVec_from1<T>(n) {};
|
||||
T sum() const {T s=0; for(int i=1; i<=this->size(); ++i) s += i*(*this)[i]; return s;}
|
||||
T nparts() const {T s=0; for(int i=1; i<=this->size(); ++i) s += (*this)[i]; return s;}
|
||||
@ -151,6 +155,7 @@ template <typename T>
|
||||
class Partition : public NRVec_from1<T> {
|
||||
public:
|
||||
Partition(): NRVec_from1<T>() {};
|
||||
template<int SIZE> explicit Partition(const T (&a)[SIZE]) : NRVec_from1<T>(a) {};
|
||||
Partition(const int n) : NRVec_from1<T>(n) {};
|
||||
T nparts() const {T s=0; for(int i=1; i<=this->size(); ++i) if((*this)[i]) ++s; return s;}
|
||||
bool is_valid() const {if(this->size() != this->sum()) return false; for(int i=2; i<=this->size(); ++i) if((*this)[i]>(*this)[i-1]) return false; return true; }
|
||||
@ -179,6 +184,8 @@ class YoungTableaux : public NRVec_from1<NRVec_from1<T> > {
|
||||
public:
|
||||
YoungTableaux() : NRVec_from1<NRVec_from1<T> >() {};
|
||||
explicit YoungTableaux(const Partition<T> &frame);
|
||||
template<int SIZE> explicit YoungTableaux(const NRVec_from1<T> (&a)[SIZE]) : NRVec_from1<NRVec_from1<T> >(a) {};
|
||||
//NOTE - how to do it so that direct nested brace initializer would work?
|
||||
|
||||
bool is_valid() const; //check whether its shape forms a partition
|
||||
int nrows() const {return this->size();}
|
||||
|
@ -32,6 +32,7 @@ template <typename T>
|
||||
class Polynomial : public NRVec<T> {
|
||||
public:
|
||||
Polynomial(): NRVec<T>() {};
|
||||
template<int SIZE> Polynomial(const T (&a)[SIZE]) : NRVec<T>(a) {};
|
||||
Polynomial(const NRVec<T> &v) : NRVec<T>(v) {}; //allow implicit conversion from NRVec
|
||||
Polynomial(const int n) : NRVec<T>(n+1) {};
|
||||
Polynomial(const T &a, const int n) : NRVec<T>(n+1) {NRVec<T>::clear(); (*this)[0]=a;};
|
||||
|
11
t.cc
11
t.cc
@ -23,6 +23,7 @@
|
||||
#include "vecmat3.h"
|
||||
#include "quaternion.h"
|
||||
#include "permutation.h"
|
||||
#include "polynomial.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace LA_Vecmat3;
|
||||
@ -2298,16 +2299,26 @@ if(1)
|
||||
{
|
||||
NRVec<int> v({1,2,3,4});
|
||||
cout <<v;
|
||||
NRVec_from1<int> vv({1,2});
|
||||
cout <<vv;
|
||||
v.resize(0);
|
||||
cout<<v;
|
||||
NRMat<int> m({{1,2,3},{4,5,6}});
|
||||
cout<<m;
|
||||
NRMat_from1<int> mm({{1,2,3},{4,5,6}});
|
||||
cout<<mm;
|
||||
Vec3<double> x({1,2,3});
|
||||
cout<<x<<endl;
|
||||
Mat3<double> y({{1,2,3},{4,5,6},{7,8,9}});
|
||||
cout <<y<<endl;
|
||||
Quaternion<double> q({1,2,3,4});
|
||||
cout<<q<<endl;
|
||||
NRPerm<int> p({1,4,2,3});
|
||||
cout <<p<<endl;
|
||||
CyclePerm<int> c({NRVec_from1({1,2}),NRVec_from1({3,4,5})});
|
||||
cout <<c;
|
||||
Polynomial<double> pp({1,2,3,4,5});
|
||||
cout<<pp;
|
||||
}
|
||||
|
||||
|
||||
|
1
vec.h
1
vec.h
@ -441,6 +441,7 @@ template<typename T>
|
||||
class NRVec_from1 : public NRVec<T> {
|
||||
public:
|
||||
NRVec_from1(): NRVec<T>() {};
|
||||
template<int SIZE> NRVec_from1(const T (&a)[SIZE]) : NRVec<T>(a) {};
|
||||
explicit NRVec_from1(const int n): NRVec<T>(n) {};
|
||||
NRVec_from1(const NRVec<T> &rhs): NRVec<T>(rhs) {};//!< be able to convert the parent class transparently to this
|
||||
NRVec_from1(const T &a, const int n): NRVec<T>(a, n) {};
|
||||
|
Loading…
Reference in New Issue
Block a user