mtl4_interface.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00003 //=====================================================
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 // #include <boost/numeric/mtl/operation/cholesky.hpp>
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 //     morton_dense<double, doppled_64_row_mask> C(N,N);
00087 //     C = B;
00088 //     X = (A*C);
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 //   static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
00120 //     C = X;
00121 //     recursive_cholesky(C);
00122 //   }
00123 
00124 //   static inline void lu_decomp(const gene_matrix & X, gene_matrix & R, int N){
00125 //     R = X;
00126 //     std::vector<int> ipvt(N);
00127 //     lu_factor(R, ipvt);
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


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:00