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


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