• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //=====================================================
2 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
3 //=====================================================
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 //
18 #ifndef BLAZE_INTERFACE_HH
19 #define BLAZE_INTERFACE_HH
20 
21 #include <blaze/Math.h>
22 #include <blaze/Blaze.h>
23 // using namespace blaze;
24 
25 #include <vector>
26 
27 template<class real>
28 class blaze_interface {
29 
30 public :
31 
32   typedef real real_type ;
33 
34   typedef std::vector<real>        stl_vector;
35   typedef std::vector<stl_vector > stl_matrix;
36 
37   typedef blaze::DynamicMatrix<real,blaze::columnMajor>  gene_matrix;
38   typedef blaze::DynamicVector<real>  gene_vector;
39 
name()40   static inline std::string name() { return "blaze"; }
41 
free_matrix(gene_matrix & A,int N)42   static void free_matrix(gene_matrix & A, int N){
43     return ;
44   }
45 
free_vector(gene_vector & B)46   static void free_vector(gene_vector & B){
47     return ;
48   }
49 
matrix_from_stl(gene_matrix & A,stl_matrix & A_stl)50   static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
51     A.resize(A_stl[0].size(), A_stl.size());
52 
53     for (int j=0; j<A_stl.size() ; j++){
54       for (int i=0; i<A_stl[j].size() ; i++){
55         A(i,j) = A_stl[j][i];
56       }
57     }
58   }
59 
vector_from_stl(gene_vector & B,stl_vector & B_stl)60   static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
61     B.resize(B_stl.size());
62     for (int i=0; i<B_stl.size() ; i++){
63       B[i] = B_stl[i];
64     }
65   }
66 
vector_to_stl(gene_vector & B,stl_vector & B_stl)67   static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
68     for (int i=0; i<B_stl.size() ; i++){
69       B_stl[i] = B[i];
70     }
71   }
72 
matrix_to_stl(gene_matrix & A,stl_matrix & A_stl)73   static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
74     int N=A_stl.size();
75     for (int j=0;j<N;j++){
76       A_stl[j].resize(N);
77       for (int i=0;i<N;i++){
78         A_stl[j][i] = A(i,j);
79       }
80     }
81   }
82 
matrix_matrix_product(const gene_matrix & A,const gene_matrix & B,gene_matrix & X,int N)83   static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
84     X = (A*B);
85   }
86 
transposed_matrix_matrix_product(const gene_matrix & A,const gene_matrix & B,gene_matrix & X,int N)87   static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
88     X = (trans(A)*trans(B));
89   }
90 
ata_product(const gene_matrix & A,gene_matrix & X,int N)91   static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){
92     X = (trans(A)*A);
93   }
94 
aat_product(const gene_matrix & A,gene_matrix & X,int N)95   static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){
96     X = (A*trans(A));
97   }
98 
matrix_vector_product(gene_matrix & A,gene_vector & B,gene_vector & X,int N)99   static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
100     X = (A*B);
101   }
102 
atv_product(gene_matrix & A,gene_vector & B,gene_vector & X,int N)103   static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
104     X = (trans(A)*B);
105   }
106 
axpy(const real coef,const gene_vector & X,gene_vector & Y,int N)107   static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
108     Y += coef * X;
109   }
110 
axpby(real a,const gene_vector & X,real b,gene_vector & Y,int N)111   static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
112     Y = a*X + b*Y;
113   }
114 
115 //   static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
116 //     C = X;
117 //     recursive_cholesky(C);
118 //   }
119 
120 //   static inline void lu_decomp(const gene_matrix & X, gene_matrix & R, int N){
121 //     R = X;
122 //     std::vector<int> ipvt(N);
123 //     lu_factor(R, ipvt);
124 //   }
125 
126 //   static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
127 //     X = lower_trisolve(L, B);
128 //   }
129 
copy_matrix(const gene_matrix & source,gene_matrix & cible,int N)130   static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
131     cible = source;
132   }
133 
copy_vector(const gene_vector & source,gene_vector & cible,int N)134   static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
135     cible = source;
136   }
137 
138 };
139 
140 #endif
141