Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/algorithms/Krylov/precond.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_PRECOND_HPP
00002 #define SKYLARK_PRECOND_HPP
00003 
00004 #include "../../base/base.hpp"
00005 
00006 namespace skylark { namespace nla {
00007 
00013 template<typename T>
00014 struct precond_t {
00015 
00017     virtual void apply(T& X) const = 0;
00018 
00019     virtual void apply_adjoint(T& X) const = 0;
00020 
00021     virtual ~precond_t() { }
00022 };
00023 
00024 #ifdef SKYLARK_HAVE_ELEMENTAL
00025 
00029 template<typename T>
00030 struct id_precond_t : public precond_t<T> {
00031     void apply(T& X) const { }
00032 
00033     void apply_adjoint(T& X) const { }
00034 };
00035 
00039 template<typename XType, typename NType>
00040 struct mat_precond_t : public precond_t<XType> {
00041     const NType& N;
00042 
00043     mat_precond_t(const NType& N) : N(N) { }
00044 
00045     void apply(XType& X) const {
00046         XType Xin(X);
00047         base::Gemm(elem::NORMAL, elem::NORMAL, 1.0, N, Xin, X);
00048     }
00049 
00050     void apply_adjoint(XType& X) const {
00051         XType Xin(X);
00052         base::Gemm(elem::ADJOINT, elem::NORMAL, 1.0, N, Xin, X);
00053     }
00054 };
00055 
00059 template<typename XType, typename RType,
00060          elem::UpperOrLower UL, elem::UnitOrNonUnit D>
00061 struct tri_inverse_precond_t : public precond_t<XType> {
00062     const RType& R;
00063 
00064     tri_inverse_precond_t(const RType& R) : R(R) { }
00065 
00066     void apply(XType& X) const {
00067         base::Trsm(elem::LEFT, UL, elem::NORMAL, D, 1.0, R, X);
00068     }
00069 
00070     void apply_adjoint(XType& X) const {
00071         base::Trsm(elem::LEFT, UL, elem::ADJOINT, D, 1.0, R, X);
00072     }
00073 };
00074 
00075 #endif
00076 
00077 } } 
00079 #endif // SKYLARK_PRECOND_HPP