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
00019
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
00046
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
00128 }
00129
00130 static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
00131 cible = source;
00132
00133
00134
00135
00136
00137
00138 }
00139
00140 static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
00141
00142 cible = source;
00143 }
00144
00145 };
00146
00147 #endif