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 
23 namespace concepts {
24 
25  // forward declaration
26  template<typename F>
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,
69  Function<F>& fncX);
70  virtual void operator()(const Function<c_type>& fncY,
71  Function<c_type>& fncX);
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,
80  Vector<F>& fncX);
81  virtual void transpMult(const Vector<c_type>& fncY,
82  Vector<c_type>& fncX);
83 
88  Matrix<F>& dest) const;
89 
93  void convertToMatrix(Matrix<F>& dest) const;
94  protected:
95  virtual std::ostream& info(std::ostream& os) const;
96  private:
99  };
100 
101  // **************************************************** TrivExtendRestrict **
102 
109  template<typename F>
110  class TrivExtendRestrict : public concepts::Operator<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 
134  TrivExtendRestrict(uint dimX, uint dimY, bool extend = false)
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 
148  virtual void operator()(const concepts::Function<F>& fncY,
149  concepts::Function<F>& fncX);
151  bool extend() const { return extend_; }
152 
156  void convertToMatrix(Matrix<F>& dest) const;
157  protected:
158  virtual std::ostream& info(std::ostream& os) const;
159  private:
160  const bool extend_;
161  };
162 
163  template<typename F>
165  (const concepts::Function<F>& fncY, concepts::Function<F>& fncX) {
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
Permutation(uint dim, const Array< int > &perm, bool transpose=false)
Trivial extension and restriction operator.
Definition: permutation.hh:27
void convertToMatrix(Matrix< F > &dest) const
Convertes this operator to the matrix dest.
Permutation operator.
Definition: permutation.hh:41
Array< int > p_
Array defining the permutation.
Definition: permutation.hh:98
Cmplxtype< F >::type c_type
Complex type of data type.
Definition: permutation.hh:46
Permutation(const Space< G > &space, const Array< int > &perm, bool transpose=false)
Constructor.
Abstract class for a function.
Definition: basis.hh:21
int operator[](const uint i) const
Returns the permutation of index i.
Definition: permutation.hh:74
virtual uint dim() const =0
Returns the dimension of the space.
void composeRestr(const TrivExtendRestrict< F > &restr, Matrix< F > &dest) const
Computes the composition of a Permutation and a TrivExtendRestrict and stores the result in dest.
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
virtual void transpMult(const Vector< c_type > &fncY, Vector< c_type > &fncX)
bool extend() const
Returns the extension flag.
Definition: permutation.hh:151
virtual void operator()(const Function< r_type > &fncY, Function< F > &fncX)
Computes fncX = A(fncY) where A is this matrix.
virtual void transpMult(const Vector< r_type > &fncY, Vector< F > &fncX)
Computes fncX = AT fncY where A is this matrix.
#define DEBUGL(doit, msg)
Exception class for assertions.
Definition: exceptions.hh:258
Abstract class for an operator.
Definition: compositions.hh:31
virtual void operator()(const concepts::Function< F > &fncY, concepts::Function< F > &fncX)
Definition: permutation.hh:165
Abstract class for an operator.
Definition: ARPACK.hh:16
TrivExtendRestrict(uint dimX, uint dimY, bool extend=false)
Definition: permutation.hh:134
Mapping< F, dim > & transpose(Mapping< F, dim > &m)
Definition: operations.hh:54
#define trivExtRestrConstr_D
Definition: permutation.hh:20
void convertToMatrix(Matrix< F > &dest) const
Convertes this permutation to the matrix dest.
virtual F operator()(const uint i, const uint j) const
Returns entry with indices i and j.
TrivExtendRestrict(const concepts::Space< G > &spcX, const concepts::Space< G > &spcY, bool extend=false)
Constructor.
Definition: permutation.hh:119
virtual F & operator()(const uint i, const uint j)
Returns and allows access to entry with indices i and j.
std::complex< F > type
Definition: typedefs.hh:116
Permutation(const Permutation< F > &perm, bool transpose=false)
Copy constructor.
Realtype< F >::type r_type
Real type of data type.
Definition: permutation.hh:44
virtual std::ostream & info(std::ostream &os) const
std::conditional< std::is_same< typename Realtype< F >::type, F >::value, typename Realtype< F >::type, typename Cmplxtype< F >::type >::type d_type
Data type, depending if F is real or complex.
Definition: permutation.hh:49
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual std::ostream & info(std::ostream &os) const
#define trivExtRestrAppl_D
Definition: permutation.hh:21
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich