• 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 MTL4_INTERFACE_HH
19 #define MTL4_INTERFACE_HH
20 
21 #include <boost/numeric/mtl/mtl.hpp>
22 #include <boost/numeric/mtl/utility/range_generator.hpp>
23 // #include <boost/numeric/mtl/operation/cholesky.hpp>
24 #include <vector>
25 
26 using namespace mtl;
27 
28 template<class real>
29 class mtl4_interface {
30 
31 public :
32 
33   typedef real real_type ;
34 
35   typedef std::vector<real>  stl_vector;
36   typedef std::vector<stl_vector > stl_matrix;
37 
38   typedef mtl::dense2D<real, mtl::matrix::parameters<mtl::tag::col_major> > gene_matrix;
39   typedef mtl::dense_vector<real>  gene_vector;
40 
name()41   static inline std::string name() { return "mtl4"; }
42 
free_matrix(gene_matrix & A,int N)43   static void free_matrix(gene_matrix & A, int N){
44     return ;
45   }
46 
free_vector(gene_vector & B)47   static void free_vector(gene_vector & B){
48     return ;
49   }
50 
matrix_from_stl(gene_matrix & A,stl_matrix & A_stl)51   static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
52     A.change_dim(A_stl[0].size(), A_stl.size());
53 
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     }
59   }
60 
vector_from_stl(gene_vector & B,stl_vector & B_stl)61   static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
62     B.change_dim(B_stl.size());
63     for (int i=0; i<B_stl.size() ; i++){
64       B[i] = B_stl[i];
65     }
66   }
67 
vector_to_stl(gene_vector & B,stl_vector & B_stl)68   static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
69     for (int i=0; i<B_stl.size() ; i++){
70       B_stl[i] = B[i];
71     }
72   }
73 
matrix_to_stl(gene_matrix & A,stl_matrix & A_stl)74   static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
75     int N=A_stl.size();
76     for (int j=0;j<N;j++){
77       A_stl[j].resize(N);
78       for (int i=0;i<N;i++){
79         A_stl[j][i] = A(i,j);
80       }
81     }
82   }
83 
matrix_matrix_product(const gene_matrix & A,const gene_matrix & B,gene_matrix & X,int N)84   static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
85     X = (A*B);
86 //     morton_dense<double, doppled_64_row_mask> C(N,N);
87 //     C = B;
88 //     X = (A*C);
89   }
90 
transposed_matrix_matrix_product(const gene_matrix & A,const gene_matrix & B,gene_matrix & X,int N)91   static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
92     X = (trans(A)*trans(B));
93   }
94 
95 //   static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){
96 //     X = (trans(A)*A);
97 //   }
98 
aat_product(const gene_matrix & A,gene_matrix & X,int N)99   static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){
100     X = (A*trans(A));
101   }
102 
matrix_vector_product(gene_matrix & A,gene_vector & B,gene_vector & X,int N)103   static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
104     X = (A*B);
105   }
106 
atv_product(gene_matrix & A,gene_vector & B,gene_vector & X,int N)107   static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
108     X = (trans(A)*B);
109   }
110 
axpy(const real coef,const gene_vector & X,gene_vector & Y,int N)111   static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
112     Y += coef * X;
113   }
114 
axpby(real a,const gene_vector & X,real b,gene_vector & Y,int N)115   static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
116     Y = a*X + b*Y;
117   }
118 
119 //   static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
120 //     C = X;
121 //     recursive_cholesky(C);
122 //   }
123 
124 //   static inline void lu_decomp(const gene_matrix & X, gene_matrix & R, int N){
125 //     R = X;
126 //     std::vector<int> ipvt(N);
127 //     lu_factor(R, ipvt);
128 //   }
129 
trisolve_lower(const gene_matrix & L,const gene_vector & B,gene_vector & X,int N)130   static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
131     X = lower_trisolve(L, B);
132   }
133 
copy_matrix(const gene_matrix & source,gene_matrix & cible,int N)134   static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
135     cible = source;
136   }
137 
copy_vector(const gene_vector & source,gene_vector & cible,int N)138   static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
139     cible = source;
140   }
141 
142 };
143 
144 #endif
145