Class documentation of Concepts

Loading...
Searching...
No Matches
permutation.hh
Go to the documentation of this file.
1
6#ifndef permutation_hh
7#define permutation_hh
8
9#include "matrix.hh"
10#include "basics/exceptions.hh"
11
12// debugging
13#include "basics/debug.hh"
14
15#include <type_traits>
16#include <typeinfo>
17
18#define PermutationAppl_D 0
19
20#define trivExtRestrConstr_D 0
21#define trivExtRestrAppl_D 0
22
23namespace concepts {
24
25 // forward declaration
26 template<typename F>
27 class TrivExtendRestrict;
28
29 // *********************************************************** Permutation **
30
40 template<typename F>
41 class Permutation : public Matrix<F> {
42 public:
44 typedef typename Realtype<F>::type r_type;
46 typedef typename Cmplxtype<F>::type c_type;
48 typedef typename std::conditional<std::is_same<typename Realtype<F>::type, F>::value ,
49 typename Realtype<F>::type, typename Cmplxtype<F>::type >::type d_type;
50
57 template<class G>
58 Permutation(const Space<G>& space,
59 const Array<int>& perm, bool transpose = false);
60
61 Permutation(uint dim, const Array<int>& perm, bool transpose = false);
66 Permutation(const Permutation<F>& perm, bool transpose = false);
67
68 virtual void operator()(const Function<r_type>& fncY,
70 virtual void operator()(const Function<c_type>& fncY,
72
74 int operator[](const uint i) const { return p_[i]; }
75
76 virtual F operator()(const uint i, const uint j) const;
77 virtual F& operator()(const uint i, const uint j);
78
79 virtual void transpMult(const Vector<r_type>& fncY,
81 virtual void transpMult(const Vector<c_type>& fncY,
83
88 Matrix<F>& dest) const;
89
94 protected:
95 virtual std::ostream& info(std::ostream& os) const;
96 private:
98 Array<int> p_;
99 };
100
101 // **************************************************** TrivExtendRestrict **
102
109 template<typename F>
111 public:
118 template<class G>
120 const concepts::Space<G>& spcY, bool extend = false)
121 : Operator<F>(spcX.dim(), spcY.dim()), extend_(extend)
122 {
123 DEBUGL(trivExtRestrConstr_D, "extend = " << extend
124 << ", dimX = " << this->dimX() << ", dimY = " << this->dimY());
125#ifdef DEBUG
126 if (extend_) {
127 conceptsAssert(spcX.dim() >= spcY.dim(), concepts::Assertion());
128 } else {
129 conceptsAssert(spcX.dim() <= spcY.dim(), concepts::Assertion());
130 }
131#endif
132 }
133
135 : Operator<F>(dimX, dimY), extend_(extend)
136 {
137 DEBUGL(trivExtRestrConstr_D, "extend = " << extend
138 << ", dimX = " << this->dimX() << ", dimY = " << this->dimY());
139#ifdef DEBUG
140 if (extend_) {
142 } else {
144 }
145#endif
146 }
147
151 bool extend() const { return extend_; }
152
157 protected:
158 virtual std::ostream& info(std::ostream& os) const;
159 private:
160 const bool extend_;
161 };
162
163 template<typename F>
166 conceptsAssert(this->dimX() == fncX.dim(), concepts::Assertion());
167 conceptsAssert(this->dimY() == fncY.dim(), concepts::Assertion());
168 DEBUGL(trivExtRestrAppl_D, "y = " << fncY);
169 const uint diff = this->dimX() > this->dimY() ?
170 this->dimX() - this->dimY() : this->dimY() - this->dimX();
171 DEBUGL(trivExtRestrAppl_D, "diff = " << diff << ", extend = " << extend_);
172 if (extend_) {
173 for (uint i = 0; i < diff; ++i) fncX(i) = 0;
174 for (uint i = 0; i < this->dimY(); ++i) fncX(i+diff) = fncY(i);
175 } else {
176 for (uint i = 0; i < this->dimX(); ++i) fncX(i) = fncY(i+diff);
177 }
178 DEBUGL(trivExtRestrAppl_D, "x = " << fncX);
179 }
180
181} // namespace concepts
182
183#endif // permutation_hh
virtual const uint dimY() const
F type
Type of data, e.g. matrix entries.
virtual const uint dimX() const
int operator[](const uint i) const
Returns the permutation of index i.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
std::conditional< std::is_same< typenameRealtype< F >::type, F >::value, typenameRealtype< F >::type, typenameCmplxtype< F >::type >::type d_type
Data type, depending if F is real or complex.
void composeRestr(const TrivExtendRestrict< F > &restr, Matrix< F > &dest) const
Permutation(const Permutation< F > &perm, bool transpose=false)
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
virtual void transpMult(const Vector< r_type > &fncY, Vector< F > &fncX)
Computes fncX = AT fncY where A is this matrix.
Cmplxtype< F >::type c_type
Complex type of data type.
virtual void operator()(const Function< r_type > &fncY, Function< F > &fncX)
Computes fncX = A(fncY) where A is this matrix.
Realtype< F >::type r_type
Real type of data type.
Permutation(const Space< G > &space, const Array< int > &perm, bool transpose=false)
void convertToMatrix(Matrix< F > &dest) const
virtual F operator()(const uint i, const uint j) const
Returns entry with indices i and j.
virtual F & operator()(const uint i, const uint j)
Returns and allows access to entry with indices i and j.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
TrivExtendRestrict(const concepts::Space< G > &spcX, const concepts::Space< G > &spcY, bool extend=false)
virtual void operator()(const concepts::Function< F > &fncY, concepts::Function< F > &fncX)
void convertToMatrix(Matrix< F > &dest) const
bool extend() const
Returns the extension flag.
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
Definition debug.hh:40
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320