action_hessenberg.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  action_hessenberg.hh
00003 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00004 //=====================================================
00005 //
00006 // This program is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU General Public License
00008 // as published by the Free Software Foundation; either version 2
00009 // of the License, or (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 #ifndef ACTION_HESSENBERG
00020 #define ACTION_HESSENBERG
00021 #include "utilities.h"
00022 #include "STL_interface.hh"
00023 #include <string>
00024 #include "init/init_function.hh"
00025 #include "init/init_vector.hh"
00026 #include "init/init_matrix.hh"
00027 
00028 using namespace std;
00029 
00030 template<class Interface>
00031 class Action_hessenberg {
00032 
00033 public :
00034 
00035   // Ctor
00036 
00037   Action_hessenberg( int size ):_size(size)
00038   {
00039     MESSAGE("Action_hessenberg Ctor");
00040 
00041     // STL vector initialization
00042     init_matrix<pseudo_random>(X_stl,_size);
00043 
00044     init_matrix<null_function>(C_stl,_size);
00045     init_matrix<null_function>(resu_stl,_size);
00046 
00047     // generic matrix and vector initialization
00048     Interface::matrix_from_stl(X_ref,X_stl);
00049     Interface::matrix_from_stl(X,X_stl);
00050     Interface::matrix_from_stl(C,C_stl);
00051 
00052     _cost = 0;
00053     for (int j=0; j<_size-2; ++j)
00054     {
00055       double r = std::max(0,_size-j-1);
00056       double b = std::max(0,_size-j-2);
00057       _cost += 6 + 3*b + r*r*4 + r*_size*4;
00058     }
00059   }
00060 
00061   // invalidate copy ctor
00062 
00063   Action_hessenberg( const  Action_hessenberg & )
00064   {
00065     INFOS("illegal call to Action_hessenberg Copy Ctor");
00066     exit(1);
00067   }
00068 
00069   // Dtor
00070 
00071   ~Action_hessenberg( void ){
00072 
00073     MESSAGE("Action_hessenberg Dtor");
00074 
00075     // deallocation
00076     Interface::free_matrix(X_ref,_size);
00077     Interface::free_matrix(X,_size);
00078     Interface::free_matrix(C,_size);
00079   }
00080 
00081   // action name
00082 
00083   static inline std::string name( void )
00084   {
00085     return "hessenberg_"+Interface::name();
00086   }
00087 
00088   double nb_op_base( void ){
00089     return _cost;
00090   }
00091 
00092   inline void initialize( void ){
00093     Interface::copy_matrix(X_ref,X,_size);
00094   }
00095 
00096   inline void calculate( void ) {
00097       Interface::hessenberg(X,C,_size);
00098   }
00099 
00100   void check_result( void ){
00101     // calculation check
00102     Interface::matrix_to_stl(C,resu_stl);
00103 
00104 //     STL_interface<typename Interface::real_type>::hessenberg(X_stl,C_stl,_size);
00105 //
00106 //     typename Interface::real_type error=
00107 //       STL_interface<typename Interface::real_type>::norm_diff(C_stl,resu_stl);
00108 //
00109 //     if (error>1.e-6){
00110 //       INFOS("WRONG CALCULATION...residual=" << error);
00111 //       exit(0);
00112 //     }
00113 
00114   }
00115 
00116 private :
00117 
00118   typename Interface::stl_matrix X_stl;
00119   typename Interface::stl_matrix C_stl;
00120   typename Interface::stl_matrix resu_stl;
00121 
00122   typename Interface::gene_matrix X_ref;
00123   typename Interface::gene_matrix X;
00124   typename Interface::gene_matrix C;
00125 
00126   int _size;
00127   double _cost;
00128 };
00129 
00130 template<class Interface>
00131 class Action_tridiagonalization {
00132 
00133 public :
00134 
00135   // Ctor
00136 
00137   Action_tridiagonalization( int size ):_size(size)
00138   {
00139     MESSAGE("Action_hessenberg Ctor");
00140 
00141     // STL vector initialization
00142     typename Interface::stl_matrix tmp;
00143     init_matrix<pseudo_random>(tmp,_size);
00144     init_matrix<null_function>(X_stl,_size);
00145     STL_interface<typename Interface::real_type>::ata_product(tmp,X_stl,_size);
00146 
00147     init_matrix<null_function>(C_stl,_size);
00148     init_matrix<null_function>(resu_stl,_size);
00149 
00150     // generic matrix and vector initialization
00151     Interface::matrix_from_stl(X_ref,X_stl);
00152     Interface::matrix_from_stl(X,X_stl);
00153     Interface::matrix_from_stl(C,C_stl);
00154 
00155     _cost = 0;
00156     for (int j=0; j<_size-2; ++j)
00157     {
00158       int r = std::max(0,_size-j-1);
00159       int b = std::max(0,_size-j-2);
00160       _cost += 6 + 3*b + r*r*8;
00161     }
00162   }
00163 
00164   // invalidate copy ctor
00165 
00166   Action_tridiagonalization( const  Action_tridiagonalization & )
00167   {
00168     INFOS("illegal call to Action_tridiagonalization Copy Ctor");
00169     exit(1);
00170   }
00171 
00172   // Dtor
00173 
00174   ~Action_tridiagonalization( void ){
00175 
00176     MESSAGE("Action_tridiagonalization Dtor");
00177 
00178     // deallocation
00179     Interface::free_matrix(X_ref,_size);
00180     Interface::free_matrix(X,_size);
00181     Interface::free_matrix(C,_size);
00182   }
00183 
00184   // action name
00185 
00186   static inline std::string name( void ) { return "tridiagonalization_"+Interface::name(); }
00187 
00188   double nb_op_base( void ){
00189     return _cost;
00190   }
00191 
00192   inline void initialize( void ){
00193     Interface::copy_matrix(X_ref,X,_size);
00194   }
00195 
00196   inline void calculate( void ) {
00197       Interface::tridiagonalization(X,C,_size);
00198   }
00199 
00200   void check_result( void ){
00201     // calculation check
00202     Interface::matrix_to_stl(C,resu_stl);
00203 
00204 //     STL_interface<typename Interface::real_type>::tridiagonalization(X_stl,C_stl,_size);
00205 //
00206 //     typename Interface::real_type error=
00207 //       STL_interface<typename Interface::real_type>::norm_diff(C_stl,resu_stl);
00208 //
00209 //     if (error>1.e-6){
00210 //       INFOS("WRONG CALCULATION...residual=" << error);
00211 //       exit(0);
00212 //     }
00213 
00214   }
00215 
00216 private :
00217 
00218   typename Interface::stl_matrix X_stl;
00219   typename Interface::stl_matrix C_stl;
00220   typename Interface::stl_matrix resu_stl;
00221 
00222   typename Interface::gene_matrix X_ref;
00223   typename Interface::gene_matrix X;
00224   typename Interface::gene_matrix C;
00225 
00226   int _size;
00227   double _cost;
00228 };
00229 
00230 #endif


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:28