Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MTL4_INTERFACE_HH
00019 #define MTL4_INTERFACE_HH
00020
00021 #include <boost/numeric/mtl/mtl.hpp>
00022 #include <boost/numeric/mtl/utility/range_generator.hpp>
00023
00024 #include <vector>
00025
00026 using namespace mtl;
00027
00028 template<class real>
00029 class mtl4_interface {
00030
00031 public :
00032
00033 typedef real real_type ;
00034
00035 typedef std::vector<real> stl_vector;
00036 typedef std::vector<stl_vector > stl_matrix;
00037
00038 typedef mtl::dense2D<real, mtl::matrix::parameters<mtl::tag::col_major> > gene_matrix;
00039 typedef mtl::dense_vector<real> gene_vector;
00040
00041 static inline std::string name() { return "mtl4"; }
00042
00043 static void free_matrix(gene_matrix & A, int N){
00044 return ;
00045 }
00046
00047 static void free_vector(gene_vector & B){
00048 return ;
00049 }
00050
00051 static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
00052 A.change_dim(A_stl[0].size(), A_stl.size());
00053
00054 for (int j=0; j<A_stl.size() ; j++){
00055 for (int i=0; i<A_stl[j].size() ; i++){
00056 A(i,j) = A_stl[j][i];
00057 }
00058 }
00059 }
00060
00061 static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
00062 B.change_dim(B_stl.size());
00063 for (int i=0; i<B_stl.size() ; i++){
00064 B[i] = B_stl[i];
00065 }
00066 }
00067
00068 static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
00069 for (int i=0; i<B_stl.size() ; i++){
00070 B_stl[i] = B[i];
00071 }
00072 }
00073
00074 static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
00075 int N=A_stl.size();
00076 for (int j=0;j<N;j++){
00077 A_stl[j].resize(N);
00078 for (int i=0;i<N;i++){
00079 A_stl[j][i] = A(i,j);
00080 }
00081 }
00082 }
00083
00084 static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
00085 X = (A*B);
00086
00087
00088
00089 }
00090
00091 static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
00092 X = (trans(A)*trans(B));
00093 }
00094
00095 static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){
00096 X = (trans(A)*A);
00097 }
00098
00099 static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){
00100 X = (A*trans(A));
00101 }
00102
00103 static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
00104 X = (A*B);
00105 }
00106
00107 static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
00108 X = (trans(A)*B);
00109 }
00110
00111 static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
00112 Y += coef * X;
00113 }
00114
00115 static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
00116 Y = a*X + b*Y;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
00131 X = lower_trisolve(L, B);
00132 }
00133
00134 static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
00135 cible = source;
00136 }
00137
00138 static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
00139 cible = source;
00140 }
00141
00142 };
00143
00144 #endif