ublas_interface.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  ublas_interface.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>
00004 // Copyright (C) EDF R&D,  lun sep 30 14:23:27 CEST 2002
00005 //=====================================================
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 //
00020 #ifndef UBLAS_INTERFACE_HH
00021 #define UBLAS_INTERFACE_HH
00022 
00023 #include <boost/numeric/ublas/vector.hpp>
00024 #include <boost/numeric/ublas/matrix.hpp>
00025 #include <boost/numeric/ublas/io.hpp>
00026 #include <boost/numeric/ublas/triangular.hpp>
00027 
00028 using namespace boost::numeric;
00029 
00030 template <class real>
00031 class ublas_interface{
00032 
00033 public :
00034 
00035   typedef real real_type ;
00036 
00037   typedef std::vector<real> stl_vector;
00038   typedef std::vector<stl_vector> stl_matrix;
00039 
00040   typedef typename boost::numeric::ublas::matrix<real,boost::numeric::ublas::column_major> gene_matrix;
00041   typedef typename boost::numeric::ublas::vector<real> gene_vector;
00042 
00043   static inline std::string name( void ) { return "ublas"; }
00044 
00045   static void free_matrix(gene_matrix & A, int N) {}
00046 
00047   static void free_vector(gene_vector & B) {}
00048 
00049   static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
00050     A.resize(A_stl.size(),A_stl[0].size());
00051     for (int j=0; j<A_stl.size() ; j++)
00052       for (int i=0; i<A_stl[j].size() ; i++)
00053         A(i,j)=A_stl[j][i];
00054   }
00055 
00056   static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
00057     B.resize(B_stl.size());
00058     for (int i=0; i<B_stl.size() ; i++)
00059       B(i)=B_stl[i];
00060   }
00061 
00062   static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
00063     for (int i=0; i<B_stl.size() ; i++)
00064       B_stl[i]=B(i);
00065   }
00066 
00067   static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
00068     int N=A_stl.size();
00069     for (int j=0;j<N;j++)
00070     {
00071       A_stl[j].resize(N);
00072       for (int i=0;i<N;i++)
00073         A_stl[j][i]=A(i,j);
00074     }
00075   }
00076 
00077   static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
00078     for (int i=0;i<N;i++){
00079       cible(i) = source(i);
00080     }
00081   }
00082 
00083   static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
00084     for (int i=0;i<N;i++){
00085       for (int j=0;j<N;j++){
00086         cible(i,j) = source(i,j);
00087       }
00088     }
00089   }
00090 
00091   static inline void matrix_vector_product_slow(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
00092     X =  prod(A,B);
00093   }
00094 
00095   static inline void matrix_matrix_product_slow(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){
00096     X =  prod(A,B);
00097   }
00098 
00099   static inline void axpy_slow(const real coef, const gene_vector & X, gene_vector & Y, int N){
00100     Y+=coef*X;
00101   }
00102 
00103   // alias free assignements
00104 
00105   static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
00106     X.assign(prod(A,B));
00107   }
00108 
00109   static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
00110     X.assign(prod(trans(A),B));
00111   }
00112 
00113   static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){
00114     X.assign(prod(A,B));
00115   }
00116 
00117   static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
00118     Y.plus_assign(coef*X);
00119   }
00120 
00121   static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
00122     Y = a*X + b*Y;
00123   }
00124 
00125   static inline void ata_product(gene_matrix & A, gene_matrix & X, int N){
00126     // X =  prod(trans(A),A);
00127     X.assign(prod(trans(A),A));
00128   }
00129 
00130   static inline void aat_product(gene_matrix & A, gene_matrix & X, int N){
00131     // X =  prod(A,trans(A));
00132     X.assign(prod(A,trans(A)));
00133   }
00134 
00135   static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
00136     X = solve(L, B, ublas::lower_tag ());
00137   }
00138 
00139 };
00140 
00141 #endif


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