algebramix_doc 0.3
/Users/mourrain/Devel/mmx/algebramix/glue/glue_matrix_generic.cpp
Go to the documentation of this file.
00001 
00002 #include <basix/vector.hpp>
00003 #include <basix/int.hpp>
00004 #include <algebramix/vector_unrolled.hpp>
00005 #include <algebramix/vector_simd.hpp>
00006 #include <numerix/integer.hpp>
00007 #include <numerix/rational.hpp>
00008 #include <algebramix/permutation.hpp>
00009 #include <basix/row_tuple.hpp>
00010 #include <algebramix/matrix.hpp>
00011 #include <algebramix/matrix_ring_naive.hpp>
00012 #include <algebramix/matrix_integer.hpp>
00013 #include <algebramix/matrix_quotient.hpp>
00014 #include <basix/tuple.hpp>
00015 #include <basix/alias.hpp>
00016 #include <basix/glue.hpp>
00017 
00018 #define int_literal(x) as_int (as_string (x))
00019 #define identity_matrix_integer identity_matrix<integer>
00020 #define hilbert_matrix_rational hilbert_matrix<rational>
00021 
00022 namespace mmx {
00023   template<typename C> matrix<C>
00024   matrix_new (const vector<row_tuple<C> >& t) {
00025     if (N(t) == 0) return matrix<C> ();
00026     nat i, j, rows= N(t), cols= N(t[0]);
00027     C dummy= 0;
00028     matrix<C> r (dummy, rows, cols);
00029     for (i=0; i<rows; i++) {
00030       ASSERT (N(t[i]) == cols, "unequal row lengths");
00031       for (j=0; j<cols; j++)
00032         r(i,j)= t[i][j];
00033     }
00034     return r;
00035   }
00036 
00037   template<typename C> matrix<C>
00038   matrix_new (const vector<C>& t) {
00039     nat j, rows= 1, cols= N(t);
00040     C dummy= 0;
00041     matrix<C> r (dummy, rows, cols);
00042     for (j=0; j<cols; j++)
00043       r(0,j)= t[j];
00044     return r;
00045   }
00046 
00047   template<typename C> vector<generic>
00048   wrap_column_reduced_echelon_with_permutation (const matrix<C>& m) {
00049     permutation permut;
00050     generic tp=as<generic> (column_reduced_echelon (m, permut));
00051     return vec (tp, as<generic> (permut));
00052   }
00053 
00054   template<typename C> vector<generic>
00055   wrap_column_reduced_echelon_with_transform (const matrix<C>& m) {
00056     matrix<C> k;
00057     generic tp=as<generic> (column_reduced_echelon (m, k));
00058     return vec (tp, as<generic> (k));
00059   }
00060 
00061   template<typename C> vector<generic>
00062   wrap_row_reduced_echelon_with_transform (const matrix<C>& m) {
00063     matrix<C> k;
00064     generic tp=as<generic> (row_reduced_echelon (m, k));
00065     return vec (tp, as<generic> (k));
00066   }
00067 }
00068 
00069 
00070 namespace mmx {
00071   static generic
00072   GLUE_1 (const int &arg_1) {
00073     return integer_construct (arg_1);
00074   }
00075   
00076   static row_tuple<generic>
00077   GLUE_2 (const tuple<generic> &arg_1) {
00078     return row_tuple<generic > (as_vector (arg_1));
00079   }
00080   
00081   static matrix<generic>
00082   GLUE_3 (const tuple<generic> &arg_1) {
00083     return matrix_new (as_vector (arg_1));
00084   }
00085   
00086   static matrix<generic>
00087   GLUE_4 (const tuple<row_tuple<generic> > &arg_1) {
00088     return matrix_new (as_vector (arg_1));
00089   }
00090   
00091   static matrix<generic>
00092   GLUE_5 (const tuple<row_tuple<generic> > &arg_1) {
00093     return matrix_new (as_vector (arg_1));
00094   }
00095   
00096   static int
00097   GLUE_6 (const matrix<generic> &arg_1) {
00098     return N (arg_1);
00099   }
00100   
00101   static int
00102   GLUE_7 (const matrix<generic> &arg_1) {
00103     return rows (arg_1);
00104   }
00105   
00106   static int
00107   GLUE_8 (const matrix<generic> &arg_1) {
00108     return cols (arg_1);
00109   }
00110   
00111   static generic
00112   GLUE_9 (const matrix<generic> &arg_1, const int &arg_2, const int &arg_3) {
00113     return arg_1 (arg_2, arg_3);
00114   }
00115   
00116   static alias<generic>
00117   GLUE_10 (const alias<matrix<generic> > &arg_1, const int &arg_2, const int &arg_3) {
00118     return alias_access<generic > (arg_1, arg_2, arg_3);
00119   }
00120   
00121   static matrix<generic>
00122   GLUE_11 (const matrix<generic> &arg_1, const int &arg_2, const int &arg_3, const int &arg_4, const int &arg_5) {
00123     return range (arg_1, arg_2, arg_3, arg_4, arg_5);
00124   }
00125   
00126   static vector<generic>
00127   GLUE_12 (const matrix<generic> &arg_1, const int &arg_2) {
00128     return row (arg_1, arg_2);
00129   }
00130   
00131   static vector<generic>
00132   GLUE_13 (const matrix<generic> &arg_1, const int &arg_2) {
00133     return column (arg_1, arg_2);
00134   }
00135   
00136   static matrix<generic>
00137   GLUE_14 (const matrix<generic> &arg_1) {
00138     return transpose (arg_1);
00139   }
00140   
00141   static matrix<generic>
00142   GLUE_15 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00143     return horizontal_join (arg_1, arg_2);
00144   }
00145   
00146   static matrix<generic>
00147   GLUE_16 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00148     return vertical_join (arg_1, arg_2);
00149   }
00150   
00151   static matrix<generic>
00152   GLUE_17 (const generic &arg_1, const int &arg_2, const int &arg_3) {
00153     return fill_matrix (arg_1, arg_2, arg_3);
00154   }
00155   
00156   static matrix<generic>
00157   GLUE_18 (const generic &arg_1, const int &arg_2) {
00158     return jordan_matrix (arg_1, arg_2);
00159   }
00160   
00161   static matrix<generic>
00162   GLUE_19 (const vector<generic> &arg_1) {
00163     return toeplitz_matrix (arg_1);
00164   }
00165   
00166   static matrix<generic>
00167   GLUE_20 (const vector<generic> &arg_1) {
00168     return hankel_matrix (arg_1);
00169   }
00170   
00171   static matrix<generic>
00172   GLUE_21 (const vector<generic> &arg_1, const vector<generic> &arg_2) {
00173     return tensor_matrix (arg_1, arg_2);
00174   }
00175   
00176   static matrix<generic>
00177   GLUE_22 (const vector<generic> &arg_1) {
00178     return vandermonde (arg_1);
00179   }
00180   
00181   static matrix<generic>
00182   GLUE_23 (const matrix<generic> &arg_1) {
00183     return -arg_1;
00184   }
00185   
00186   static matrix<generic>
00187   GLUE_24 (const matrix<generic> &arg_1) {
00188     return square (arg_1);
00189   }
00190   
00191   static matrix<generic>
00192   GLUE_25 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00193     return arg_1 + arg_2;
00194   }
00195   
00196   static matrix<generic>
00197   GLUE_26 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00198     return arg_1 - arg_2;
00199   }
00200   
00201   static matrix<generic>
00202   GLUE_27 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00203     return arg_1 * arg_2;
00204   }
00205   
00206   static vector<generic>
00207   GLUE_28 (const matrix<generic> &arg_1, const vector<generic> &arg_2) {
00208     return arg_1 * arg_2;
00209   }
00210   
00211   static vector<generic>
00212   GLUE_29 (const vector<generic> &arg_1, const matrix<generic> &arg_2) {
00213     return arg_1 * arg_2;
00214   }
00215   
00216   static matrix<generic>
00217   GLUE_30 (const matrix<generic> &arg_1, const matrix<generic> &arg_2) {
00218     return krylov (arg_1, arg_2);
00219   }
00220   
00221   static generic
00222   GLUE_31 (const matrix<generic> &arg_1) {
00223     return det (arg_1);
00224   }
00225   
00226   static matrix<generic>
00227   GLUE_32 (const matrix<generic> &arg_1) {
00228     return row_echelon (arg_1);
00229   }
00230   
00231   static matrix<generic>
00232   GLUE_33 (const matrix<generic> &arg_1) {
00233     return column_echelon (arg_1);
00234   }
00235   
00236   static matrix<generic>
00237   GLUE_34 (const matrix<generic> &arg_1) {
00238     return row_reduced_echelon (arg_1);
00239   }
00240   
00241   static matrix<generic>
00242   GLUE_35 (const matrix<generic> &arg_1) {
00243     return column_reduced_echelon (arg_1);
00244   }
00245   
00246   static vector<generic>
00247   GLUE_36 (const matrix<generic> &arg_1) {
00248     return wrap_row_reduced_echelon_with_transform (arg_1);
00249   }
00250   
00251   static vector<generic>
00252   GLUE_37 (const matrix<generic> &arg_1) {
00253     return wrap_column_reduced_echelon_with_transform (arg_1);
00254   }
00255   
00256   static vector<generic>
00257   GLUE_38 (const matrix<generic> &arg_1) {
00258     return wrap_column_reduced_echelon_with_permutation (arg_1);
00259   }
00260   
00261   static matrix<generic>
00262   GLUE_39 (const matrix<generic> &arg_1) {
00263     return kernel (arg_1);
00264   }
00265   
00266   static matrix<generic>
00267   GLUE_40 (const matrix<generic> &arg_1) {
00268     return image (arg_1);
00269   }
00270   
00271   static int
00272   GLUE_41 (const matrix<generic> &arg_1) {
00273     return rank (arg_1);
00274   }
00275   
00276   static matrix<generic>
00277   GLUE_42 (const matrix<generic> &arg_1) {
00278     return invert (arg_1);
00279   }
00280   
00281   static matrix<generic>
00282   GLUE_43 (const matrix<generic> &arg_1) {
00283     return derive (arg_1);
00284   }
00285   
00286   static matrix<generic>
00287   GLUE_44 (const matrix<generic> &arg_1) {
00288     return integrate (arg_1);
00289   }
00290   
00291   void
00292   glue_matrix_generic () {
00293     static bool done = false;
00294     if (done) return;
00295     done = true;
00296     call_glue (string ("glue_vector_generic"));
00297     call_glue (string ("glue_vector_int"));
00298     define_constructor<int > (GLUE_1);
00299     define_type<row_tuple<generic> > (gen (lit ("Row"), lit ("Generic")));
00300     define_type<matrix<generic> > (gen (lit ("Matrix"), lit ("Generic")));
00301     define ("(.)", GLUE_2);
00302     define ("matrix", GLUE_3);
00303     define ("matrix", GLUE_4);
00304     define ("[]", GLUE_5);
00305     define ("#", GLUE_6);
00306     define ("rows", GLUE_7);
00307     define ("columns", GLUE_8);
00308     define (".[]", GLUE_9);
00309     define (".[]", GLUE_10);
00310     define (".[]", GLUE_11);
00311     define ("row", GLUE_12);
00312     define ("column", GLUE_13);
00313     define ("transpose", GLUE_14);
00314     define ("horizontal_join", GLUE_15);
00315     define ("vertical_join", GLUE_16);
00316     define ("fill_matrix", GLUE_17);
00317     define ("jordan_matrix", GLUE_18);
00318     define ("toeplitz_matrix", GLUE_19);
00319     define ("hankel_matrix", GLUE_20);
00320     define ("tensor_matrix", GLUE_21);
00321     define ("vandermonde", GLUE_22);
00322     define ("-", GLUE_23);
00323     define ("square", GLUE_24);
00324     define ("+", GLUE_25);
00325     define ("-", GLUE_26);
00326     define ("*", GLUE_27);
00327     define ("*", GLUE_28);
00328     define ("*", GLUE_29);
00329     define ("krylov", GLUE_30);
00330     define ("det", GLUE_31);
00331     define ("row_echelon", GLUE_32);
00332     define ("column_echelon", GLUE_33);
00333     define ("row_reduced_echelon", GLUE_34);
00334     define ("column_reduced_echelon", GLUE_35);
00335     define ("row_reduced_echelon_with_transform", GLUE_36);
00336     define ("column_reduced_echelon_with_transform", GLUE_37);
00337     define ("column_reduced_echelon_with_permutation", GLUE_38);
00338     define ("ker", GLUE_39);
00339     define ("im", GLUE_40);
00340     define ("rank", GLUE_41);
00341     define ("invert", GLUE_42);
00342     define ("derive", GLUE_43);
00343     define ("integrate", GLUE_44);
00344   }
00345 }
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines