action_cholesky.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  action_cholesky.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_CHOLESKY
00020 #define ACTION_CHOLESKY
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_cholesky {
00032 
00033 public :
00034 
00035   // Ctor
00036 
00037   Action_cholesky( int size ):_size(size)
00038   {
00039     MESSAGE("Action_cholesky Ctor");
00040 
00041     // STL mat/vec initialization
00042     init_matrix_symm<pseudo_random>(X_stl,_size);
00043     init_matrix<null_function>(C_stl,_size);
00044 
00045     // make sure X is invertible
00046     for (int i=0; i<_size; ++i)
00047       X_stl[i][i] = std::abs(X_stl[i][i]) * 1e2 + 100;
00048 
00049     // generic matrix and vector initialization
00050     Interface::matrix_from_stl(X_ref,X_stl);
00051     Interface::matrix_from_stl(X,X_stl);
00052     Interface::matrix_from_stl(C,C_stl);
00053 
00054     _cost = 0;
00055     for (int j=0; j<_size; ++j)
00056     {
00057       double r = std::max(_size - j -1,0);
00058       _cost += 2*(r*j+r+j);
00059     }
00060   }
00061 
00062   // invalidate copy ctor
00063 
00064   Action_cholesky( const  Action_cholesky & )
00065   {
00066     INFOS("illegal call to Action_cholesky Copy Ctor");
00067     exit(1);
00068   }
00069 
00070   // Dtor
00071 
00072   ~Action_cholesky( void ){
00073 
00074     MESSAGE("Action_cholesky Dtor");
00075 
00076     // deallocation
00077     Interface::free_matrix(X_ref,_size);
00078     Interface::free_matrix(X,_size);
00079     Interface::free_matrix(C,_size);
00080   }
00081 
00082   // action name
00083 
00084   static inline std::string name( void )
00085   {
00086     return "cholesky_"+Interface::name();
00087   }
00088 
00089   double nb_op_base( void ){
00090     return _cost;
00091   }
00092 
00093   inline void initialize( void ){
00094     Interface::copy_matrix(X_ref,X,_size);
00095   }
00096 
00097   inline void calculate( void ) {
00098       Interface::cholesky(X,C,_size);
00099   }
00100 
00101   void check_result( void ){
00102     // calculation check
00103 //     STL_interface<typename Interface::real_type>::cholesky(X_stl,C_stl,_size);
00104 //
00105 //     typename Interface::real_type error=
00106 //       STL_interface<typename Interface::real_type>::norm_diff(C_stl,resu_stl);
00107 //
00108 //     if (error>1.e-6){
00109 //       INFOS("WRONG CALCULATION...residual=" << error);
00110 //       exit(0);
00111 //     }
00112 
00113   }
00114 
00115 private :
00116 
00117   typename Interface::stl_matrix X_stl;
00118   typename Interface::stl_matrix C_stl;
00119 
00120   typename Interface::gene_matrix X_ref;
00121   typename Interface::gene_matrix X;
00122   typename Interface::gene_matrix C;
00123 
00124   int _size;
00125   double _cost;
00126 };
00127 
00128 #endif


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