STL_algo_interface.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  STL_algo_interface.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>
00004 // Copyright (C) EDF R&D,  lun sep 30 14:23:24 CEST 2002
00005 //=====================================================
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 //
00020 #ifndef STL_ALGO_INTERFACE_HH
00021 #define STL_ALGO_INTERFACE_HH
00022 #include <string>
00023 #include <vector>
00024 #include <numeric>
00025 #include <algorithm>
00026 #include "utilities.h"
00027 
00028 
00029 template<class real>
00030 class STL_algo_interface{
00031 
00032 public :
00033 
00034   typedef real real_type ;
00035 
00036   typedef std::vector<real>  stl_vector;
00037   typedef std::vector<stl_vector > stl_matrix;
00038 
00039   typedef stl_matrix gene_matrix;
00040 
00041   typedef stl_vector gene_vector;
00042 
00043   static inline std::string name( void )
00044   {
00045     return "STL_algo";
00046   }
00047 
00048   static void free_matrix(gene_matrix & A, int N){}
00049 
00050   static void free_vector(gene_vector & B){}
00051 
00052   static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
00053     A=A_stl ;
00054   }
00055 
00056   static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
00057     B=B_stl ;
00058   }
00059 
00060   static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
00061     B_stl=B ;
00062   }
00063 
00064   static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
00065     A_stl=A ;
00066   }
00067 
00068   static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
00069     for (int i=0;i<N;i++)
00070       cible[i]=source[i];
00071   }
00072 
00073   static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N)
00074   {
00075     for (int i=0;i<N;i++){
00076       for (int j=0;j<N;j++){
00077         cible[i][j]=source[i][j];
00078       }
00079     }
00080   }
00081 
00082   class somme {
00083   public:
00084 
00085     somme(real coef):_coef(coef){};
00086 
00087     real operator()(const real & val1, const real & val2)
00088     {
00089       return _coef * val1 + val2;
00090     }
00091 
00092   private:
00093 
00094     real _coef;
00095 
00096   };
00097 
00098 
00099   class vector_generator {
00100   public:
00101 
00102     vector_generator(const gene_matrix & a_matrix, const gene_vector & a_vector):
00103       _matrice(a_matrix),
00104       _vecteur(a_vector),
00105       _index(0)
00106     {};
00107     real operator()( void )
00108     {
00109 
00110       const  gene_vector & ai=_matrice[_index];
00111       int N=ai.size();
00112 
00113       _index++;
00114 
00115       return std::inner_product(&ai[0],&ai[N],&_vecteur[0],0.0);
00116     }
00117 
00118   private:
00119 
00120     int _index;
00121     const gene_matrix & _matrice;
00122     const gene_vector & _vecteur;
00123 
00124   };
00125 
00126   static inline void atv_product(const gene_matrix & A, const gene_vector & B, gene_vector & X, int N)
00127   {
00128     std::generate(&X[0],&X[N],vector_generator(A,B));
00129   }
00130 
00131   static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N)
00132   {
00133     std::transform(&X[0],&X[N],&Y[0],&Y[0],somme(coef));
00134   }
00135 
00136 };
00137 
00138 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:00