• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include "blitz/array.h"
24 #include "blitz/tiny.h"
25 #include "blitz/tinymat.h"
26 #include "blitz/tinyvec.h"
27 #include <blitz/tinyvec-et.h>
28 
29 #include <vector>
30 
31 BZ_USING_NAMESPACE(blitz)
32 
33 template<class real, int SIZE>
34 class tiny_blitz_interface
35 {
36 
37 public :
38 
39   typedef real real_type ;
40 
41   typedef std::vector<real>  stl_vector;
42   typedef std::vector<stl_vector > stl_matrix;
43 
44   typedef TinyVector<real,SIZE> gene_vector;
45   typedef TinyMatrix<real,SIZE,SIZE> gene_matrix;
46 
name()47   static inline std::string name() { return "tiny_blitz"; }
48 
free_matrix(gene_matrix & A,int N)49   static void free_matrix(gene_matrix & A, int N){}
50 
free_vector(gene_vector & B)51   static void free_vector(gene_vector & B){}
52 
matrix_from_stl(gene_matrix & A,stl_matrix & A_stl)53   static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
54     for (int j=0; j<A_stl.size() ; j++)
55       for (int i=0; i<A_stl[j].size() ; i++)
56         A(i,j)=A_stl[j][i];
57   }
58 
vector_from_stl(gene_vector & B,stl_vector & B_stl)59   static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
60     for (int i=0; i<B_stl.size() ; i++)
61       B(i) = B_stl[i];
62   }
63 
vector_to_stl(gene_vector & B,stl_vector & B_stl)64   static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
65     for (int i=0; i<B_stl.size() ; i++)
66       B_stl[i] = B(i);
67   }
68 
matrix_to_stl(gene_matrix & A,stl_matrix & A_stl)69   static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
70     int N = A_stl.size();
71     for (int j=0;j<N;j++)
72     {
73       A_stl[j].resize(N);
74       for (int i=0;i<N;i++)
75         A_stl[j][i] = A(i,j);
76     }
77   }
78 
copy_matrix(const gene_matrix & source,gene_matrix & cible,int N)79   static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
80     for (int j=0;j<N;j++)
81       for (int i=0;i<N;i++)
82         cible(i,j) = source(i,j);
83   }
84 
copy_vector(const gene_vector & source,gene_vector & cible,int N)85   static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
86     for (int i=0;i<N;i++){
87       cible(i) = source(i);
88     }
89   }
90 
matrix_matrix_product(const gene_matrix & A,const gene_matrix & B,gene_matrix & X,int N)91   static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
92     X = product(A,B);
93   }
94 
matrix_vector_product(gene_matrix & A,gene_vector & B,gene_vector & X,int N)95   static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
96     X = product(A,B);
97   }
98 
axpy(const real coef,const gene_vector & X,gene_vector & Y,int N)99   static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
100     Y += coef * X;
101   }
102 
103 };
104 
105 
106 #endif
107