You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

  1. //=====================================================
  2. // File : action_lu_decomp.hh
  3. // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
  4. //=====================================================
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public License
  8. // as published by the Free Software Foundation; either version 2
  9. // of the License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. //
  19. #ifndef ACTION_LU_DECOMP
  20. #define ACTION_LU_DECOMP
  21. #include "utilities.h"
  22. #include "STL_interface.hh"
  23. #include <string>
  24. #include "init/init_function.hh"
  25. #include "init/init_vector.hh"
  26. #include "init/init_matrix.hh"
  27. using namespace std;
  28. template<class Interface>
  29. class Action_lu_decomp {
  30. public :
  31. // Ctor
  32. Action_lu_decomp( int size ):_size(size)
  33. {
  34. MESSAGE("Action_lu_decomp Ctor");
  35. // STL vector initialization
  36. init_matrix<pseudo_random>(X_stl,_size);
  37. init_matrix<null_function>(C_stl,_size);
  38. init_matrix<null_function>(resu_stl,_size);
  39. // generic matrix and vector initialization
  40. Interface::matrix_from_stl(X_ref,X_stl);
  41. Interface::matrix_from_stl(X,X_stl);
  42. Interface::matrix_from_stl(C,C_stl);
  43. _cost = 2.0*size*size*size/3.0 + size*size;
  44. }
  45. // invalidate copy ctor
  46. Action_lu_decomp( const Action_lu_decomp & )
  47. {
  48. INFOS("illegal call to Action_lu_decomp Copy Ctor");
  49. exit(1);
  50. }
  51. // Dtor
  52. ~Action_lu_decomp( void ){
  53. MESSAGE("Action_lu_decomp Dtor");
  54. // deallocation
  55. Interface::free_matrix(X_ref,_size);
  56. Interface::free_matrix(X,_size);
  57. Interface::free_matrix(C,_size);
  58. }
  59. // action name
  60. static inline std::string name( void )
  61. {
  62. return "complete_lu_decomp_"+Interface::name();
  63. }
  64. double nb_op_base( void ){
  65. return _cost;
  66. }
  67. inline void initialize( void ){
  68. Interface::copy_matrix(X_ref,X,_size);
  69. }
  70. inline void calculate( void ) {
  71. Interface::lu_decomp(X,C,_size);
  72. }
  73. void check_result( void ){
  74. // calculation check
  75. Interface::matrix_to_stl(C,resu_stl);
  76. // STL_interface<typename Interface::real_type>::lu_decomp(X_stl,C_stl,_size);
  77. //
  78. // typename Interface::real_type error=
  79. // STL_interface<typename Interface::real_type>::norm_diff(C_stl,resu_stl);
  80. //
  81. // if (error>1.e-6){
  82. // INFOS("WRONG CALCULATION...residual=" << error);
  83. // exit(0);
  84. // }
  85. }
  86. private :
  87. typename Interface::stl_matrix X_stl;
  88. typename Interface::stl_matrix C_stl;
  89. typename Interface::stl_matrix resu_stl;
  90. typename Interface::gene_matrix X_ref;
  91. typename Interface::gene_matrix X;
  92. typename Interface::gene_matrix C;
  93. int _size;
  94. double _cost;
  95. };
  96. #endif