Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

operator/permutation.hh
Go to the documentation of this file.
00001 // permutation and restriction/extension operator
00002 
00003 #ifndef permutation_hh
00004 #define permutation_hh
00005 
00006 #include "matrix.hh"
00007 #include "basics/exceptions.hh"
00008 
00009 // debugging
00010 #include "basics/debug.hh"
00011 
00012 #define PermutationAppl_D    0
00013 
00014 #define trivExtRestrConstr_D 0
00015 #define trivExtRestrAppl_D   0
00016 
00017 namespace concepts {
00018 
00019   // forward declaration
00020   template<typename F>
00021   class TrivExtendRestrict;
00022 
00023   // *********************************************************** Permutation **
00024 
00034   template<typename F>
00035   class Permutation : public Matrix<F> {
00036   public:
00038     typedef typename Realtype<F>::type  r_type;
00040     typedef typename Cmplxtype<F>::type c_type;
00041 
00048     template<class G>
00049     Permutation(const Space<G>& space,
00050                 const Array<int>& perm, bool transpose = false);
00051 
00052     Permutation(uint dim, const Array<int>& perm, bool transpose = false);
00057     Permutation(const Permutation<F>& perm, bool transpose = false);
00058 
00059     virtual void operator()(const Function<r_type>& fncY,
00060                             Function<F>& fncX);
00061     virtual void operator()(const Function<c_type>& fncY,
00062                             Function<c_type>& fncX);
00063 
00065     int operator[](const uint i) const { return p_[i]; }
00066 
00067     virtual F operator()(const uint i, const uint j) const;
00068     virtual F& operator()(const uint i, const uint j);
00069 
00070     virtual void transpMult(const Vector<r_type>& fncY,
00071                             Vector<F>& fncX);
00072     virtual void transpMult(const Vector<c_type>& fncY,
00073                             Vector<c_type>& fncX);
00074 
00078     void composeRestr(const TrivExtendRestrict<F>& restr,
00079                       Matrix<F>& dest) const;
00080 
00084     void convertToMatrix(Matrix<F>& dest) const;
00085   protected:
00086     virtual std::ostream& info(std::ostream& os) const;
00087   private:
00089     Array<int> p_;
00090   };
00091 
00092   // **************************************************** TrivExtendRestrict **
00093 
00100   template<typename F>
00101   class TrivExtendRestrict : public concepts::Operator<F> {
00102   public:
00109     template<class G>
00110     TrivExtendRestrict(const concepts::Space<G>& spcX,
00111                        const concepts::Space<G>& spcY, bool extend = false)
00112       : Operator<F>(spcX.dim(), spcY.dim()), extend_(extend)
00113     {
00114       DEBUGL(trivExtRestrConstr_D, "extend = " << extend
00115              << ", dimX = " << this->dimX() << ", dimY = " << this->dimY());
00116 #ifdef DEBUG
00117       if (extend_) {
00118         conceptsAssert(spcX.dim() >= spcY.dim(), concepts::Assertion());
00119       } else {
00120         conceptsAssert(spcX.dim() <= spcY.dim(), concepts::Assertion());
00121       }
00122 #endif
00123     }
00124 
00125     TrivExtendRestrict(uint dimX, uint dimY, bool extend = false)
00126       : Operator<F>(dimX, dimY), extend_(extend)
00127     {
00128       DEBUGL(trivExtRestrConstr_D, "extend = " << extend
00129              << ", dimX = " << this->dimX() << ", dimY = " << this->dimY());
00130 #ifdef DEBUG
00131       if (extend_) {
00132         conceptsAssert(dimX >= dimY, concepts::Assertion());
00133       } else {
00134         conceptsAssert(dimX <= dimY, concepts::Assertion());
00135       }
00136 #endif
00137     }
00138 
00139     virtual void operator()(const concepts::Function<F>& fncY,
00140                             concepts::Function<F>& fncX);
00142     bool extend() const { return extend_; }
00143 
00147     void convertToMatrix(Matrix<F>& dest) const;
00148   protected:
00149     virtual std::ostream& info(std::ostream& os) const;
00150   private:
00151     const bool extend_;
00152   };
00153 
00154   template<typename F>
00155   void TrivExtendRestrict<F>::operator()
00156     (const concepts::Function<F>& fncY, concepts::Function<F>& fncX) {
00157     conceptsAssert(this->dimX() == fncX.dim(), concepts::Assertion());
00158     conceptsAssert(this->dimY() == fncY.dim(), concepts::Assertion());
00159     DEBUGL(trivExtRestrAppl_D, "y = " << fncY);
00160     const uint diff = this->dimX() > this->dimY() ? 
00161       this->dimX() - this->dimY() : this->dimY() - this->dimX();
00162     DEBUGL(trivExtRestrAppl_D, "diff = " << diff << ", extend = " << extend_);
00163     if (extend_) {
00164       for (uint i = 0; i < diff; ++i) fncX(i) = 0;
00165       for (uint i = 0; i < this->dimY(); ++i) fncX(i+diff) = fncY(i);
00166     } else {
00167       for (uint i = 0; i < this->dimX(); ++i) fncX(i) = fncY(i+diff);
00168     }
00169     DEBUGL(trivExtRestrAppl_D, "x = " << fncX);
00170   }
00171 
00172 } // namespace concepts
00173 
00174 #endif // permutation_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)