tiny_blitz_interface.hh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //=====================================================
  2. // File : tiny_blitz_interface.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:30 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 TINY_BLITZ_INTERFACE_HH
  21. #define TINY_BLITZ_INTERFACE_HH
  22. #include "blitz/array.h"
  23. #include "blitz/tiny.h"
  24. #include "blitz/tinymat.h"
  25. #include "blitz/tinyvec.h"
  26. #include <blitz/tinyvec-et.h>
  27. #include <vector>
  28. BZ_USING_NAMESPACE(blitz)
  29. template<class real, int SIZE>
  30. class tiny_blitz_interface
  31. {
  32. public :
  33. typedef real real_type ;
  34. typedef std::vector<real> stl_vector;
  35. typedef std::vector<stl_vector > stl_matrix;
  36. typedef TinyVector<real,SIZE> gene_vector;
  37. typedef TinyMatrix<real,SIZE,SIZE> gene_matrix;
  38. static inline std::string name() { return "tiny_blitz"; }
  39. static void free_matrix(gene_matrix & A, int N){}
  40. static void free_vector(gene_vector & B){}
  41. static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
  42. for (int j=0; j<A_stl.size() ; j++)
  43. for (int i=0; i<A_stl[j].size() ; i++)
  44. A(i,j)=A_stl[j][i];
  45. }
  46. static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
  47. for (int i=0; i<B_stl.size() ; i++)
  48. B(i) = B_stl[i];
  49. }
  50. static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
  51. for (int i=0; i<B_stl.size() ; i++)
  52. B_stl[i] = B(i);
  53. }
  54. static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
  55. int N = A_stl.size();
  56. for (int j=0;j<N;j++)
  57. {
  58. A_stl[j].resize(N);
  59. for (int i=0;i<N;i++)
  60. A_stl[j][i] = A(i,j);
  61. }
  62. }
  63. static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
  64. for (int j=0;j<N;j++)
  65. for (int i=0;i<N;i++)
  66. cible(i,j) = source(i,j);
  67. }
  68. static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
  69. for (int i=0;i<N;i++){
  70. cible(i) = source(i);
  71. }
  72. }
  73. static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  74. X = product(A,B);
  75. }
  76. static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  77. X = product(A,B);
  78. }
  79. static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
  80. Y += coef * X;
  81. }
  82. };
  83. #endif