From 9c6ab037cf5181dfe96655cd0e4c56d637e5a42a Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Thu, 28 Oct 2021 20:44:05 +0200 Subject: [PATCH] contructors from braced list for permutations and polynomials --- mat.h | 1 + permutation.h | 7 +++++++ polynomial.h | 1 + t.cc | 11 +++++++++++ vec.h | 1 + 5 files changed, 21 insertions(+) diff --git a/mat.h b/mat.h index 4391179..3f3c659 100644 --- a/mat.h +++ b/mat.h @@ -1325,6 +1325,7 @@ template class NRMat_from1 : public NRMat { public: NRMat_from1(): NRMat() {}; + template explicit NRMat_from1(const T (&a)[R][C]) : NRMat(a) {}; explicit NRMat_from1(const int n): NRMat(n) {}; explicit NRMat_from1(const NRSMat_from1 &rhs) : NRMat(rhs) {}; NRMat_from1(const NRMat &rhs): NRMat(rhs) {};//!< be able to convert the parent class transparently to this diff --git a/permutation.h b/permutation.h index 9427835..1ab744a 100644 --- a/permutation.h +++ b/permutation.h @@ -41,6 +41,7 @@ class NRPerm : public NRVec_from1 { public: //basic constructors NRPerm(): NRVec_from1() {}; + template explicit NRPerm(const T (&a)[SIZE]) : NRVec_from1(a) {}; NRPerm(const int n) : NRVec_from1(n) {}; NRPerm(const NRVec_from1 &rhs): NRVec_from1(rhs) {}; NRPerm(const T *a, const int n): NRVec_from1(a, n) {}; @@ -74,6 +75,8 @@ template class CyclePerm : public NRVec_from1 > { public: CyclePerm() : NRVec_from1 >() {}; + template explicit CyclePerm(const NRVec_from1 (&a)[SIZE]) : NRVec_from1 >(a) {}; +//NOTE - how to do it so that direct nested brace initializer would work? explicit CyclePerm(const NRPerm &rhs); bool is_valid() const; //is it really a permutation @@ -132,6 +135,7 @@ template class CompressedPartition : public NRVec_from1 { public: CompressedPartition(): NRVec_from1() {}; + template explicit CompressedPartition(const T (&a)[SIZE]) : NRVec_from1(a) {}; CompressedPartition(const int n) : NRVec_from1(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 class Partition : public NRVec_from1 { public: Partition(): NRVec_from1() {}; + template explicit Partition(const T (&a)[SIZE]) : NRVec_from1(a) {}; Partition(const int n) : NRVec_from1(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 > { public: YoungTableaux() : NRVec_from1 >() {}; explicit YoungTableaux(const Partition &frame); + template explicit YoungTableaux(const NRVec_from1 (&a)[SIZE]) : NRVec_from1 >(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();} diff --git a/polynomial.h b/polynomial.h index 6afc932..f7f41f8 100644 --- a/polynomial.h +++ b/polynomial.h @@ -32,6 +32,7 @@ template class Polynomial : public NRVec { public: Polynomial(): NRVec() {}; + template Polynomial(const T (&a)[SIZE]) : NRVec(a) {}; Polynomial(const NRVec &v) : NRVec(v) {}; //allow implicit conversion from NRVec Polynomial(const int n) : NRVec(n+1) {}; Polynomial(const T &a, const int n) : NRVec(n+1) {NRVec::clear(); (*this)[0]=a;}; diff --git a/t.cc b/t.cc index 017e0e8..7bac655 100644 --- a/t.cc +++ b/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 v({1,2,3,4}); cout < vv({1,2}); +cout < m({{1,2,3},{4,5,6}}); cout< mm({{1,2,3},{4,5,6}}); +cout< x({1,2,3}); cout< y({{1,2,3},{4,5,6},{7,8,9}}); cout < q({1,2,3,4}); cout< p({1,4,2,3}); +cout < c({NRVec_from1({1,2}),NRVec_from1({3,4,5})}); +cout < pp({1,2,3,4,5}); +cout< class NRVec_from1 : public NRVec { public: NRVec_from1(): NRVec() {}; + template NRVec_from1(const T (&a)[SIZE]) : NRVec(a) {}; explicit NRVec_from1(const int n): NRVec(n) {}; NRVec_from1(const NRVec &rhs): NRVec(rhs) {};//!< be able to convert the parent class transparently to this NRVec_from1(const T &a, const int n): NRVec(a, n) {};