init_matrix.hh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //=====================================================
  2. // File : init_matrix.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002
  5. //=====================================================
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. #ifndef INIT_MATRIX_HH
  21. #define INIT_MATRIX_HH
  22. // The Vector class must satisfy the following part of STL vector concept :
  23. // resize() method
  24. // [] operator for setting element
  25. // value_type defined
  26. template<double init_function(int,int), class Vector>
  27. BTL_DONT_INLINE void init_row(Vector & X, int size, int row){
  28. X.resize(size);
  29. for (unsigned int j=0;j<X.size();j++){
  30. X[j]=typename Vector::value_type(init_function(row,j));
  31. }
  32. }
  33. // Matrix is a Vector of Vector
  34. // The Matrix class must satisfy the following part of STL vector concept :
  35. // resize() method
  36. // [] operator for setting rows
  37. template<double init_function(int,int),class Vector>
  38. BTL_DONT_INLINE void init_matrix(Vector & A, int size){
  39. A.resize(size);
  40. for (unsigned int row=0; row<A.size() ; row++){
  41. init_row<init_function>(A[row],size,row);
  42. }
  43. }
  44. template<double init_function(int,int),class Matrix>
  45. BTL_DONT_INLINE void init_matrix_symm(Matrix& A, int size){
  46. A.resize(size);
  47. for (unsigned int row=0; row<A.size() ; row++)
  48. A[row].resize(size);
  49. for (unsigned int row=0; row<A.size() ; row++){
  50. A[row][row] = init_function(row,row);
  51. for (unsigned int col=0; col<row ; col++){
  52. double x = init_function(row,col);
  53. A[row][col] = A[col][row] = x;
  54. }
  55. }
  56. }
  57. #endif